使用外部工具从 php 缩放图像

发布于 2024-10-01 04:22:48 字数 223 浏览 0 评论 0原文

在 php 项目中,我遇到问题,我的提供程序不允许我将脚本的内存限制设置得更高。因此,如果用户上传一个巨大的图像文件,并且我尝试缩小它以确保其在服务器上的安全,我的脚本就会中断。

我的想法是运行 exec() 命令来使用外部工具,但没有找到任何示例。可以这样做吗?或者我应该在上传之前尝试使用javascript缩小图像?

还是有其他方法可以处理,我什至没有想过..?

感谢您的帮助!

In a php project I have the problem, that my provider doesn't allow me to set the memory-limit of my script higher. Therefore my script breaks if a user uploads a huge image file and I try to scale it down to safe it on the server.

My idea was to run an exec() command to use an external tool but did not find any examples. Is it possible to do so? Or should I try to scale the image down before upload, using javascript?

Or is there an other way to handle, I haven't even thought about..?

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淑女气质 2024-10-08 04:22:48

使用具有调整大小/缩放功能的客户端上传程序。这将确保大图像在到达您的服务器之前被缩小。 JumpLoader 是一个不错的选择。

Use a client-side uploader with resizing/scaling capabilities. This will make sure that big images are scaled down before reaching your server. JumpLoader is a good one.

人生戏 2024-10-08 04:22:48

您可以尝试

exec("convert source_image.jpg -resize 64x64 target_image.jpg")

查看ImageMagick是否可用。

You can try a

exec("convert source_image.jpg -resize 64x64 target_image.jpg")

to see whether ImageMagick is available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文