可以在PHP中使用ImageMagick(转换)命令
I want to edit images using ImageMagick and PHP on my website.
I'm on Linux (Raspbian OS) and have PHP and ImageMagick installed.
I'm trying to do something similar to: `convert test.png test.webp` using PHP. All work in the Terminal.
What I've tried:
putenv("PATH=/usr/local/bin:/usr/bin:/bin");
完整命令路径“/usr/bin/convert test.png test.webp
”(在终端中工作)
所有 PHP CMD 命令包括: exec()
shell_exec()
system()
passthru()
(所有这些输出都是空的,但是像 echo $PWD
这样的简单命令有效)
图像完整路径“convert /home/pi/www/test.png /home/pi/www/test.webp
”(以及所有上述变体)
非常感谢任何帮助!
I want to edit images using ImageMagick and PHP on my website.
I'm on Linux (Raspbian OS) and have PHP and ImageMagick installed.
I'm trying to do something similar to: `convert test.png test.webp` using PHP. All work in the Terminal.
What I've tried:
putenv("PATH=/usr/local/bin:/usr/bin:/bin");
Full command path "/usr/bin/convert test.png test.webp
" (Work in Terminal)
All of the PHP CMD commands including: exec()
shell_exec()
system()
passthru()
(All of the output of those were empty, but simple commands like echo $PWD
worked)
Images Full Path "convert /home/pi/www/test.png /home/pi/www/test.webp
" (And all of the above variations)
Any help in hugely appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 php shell_exec 命令中使用 2>&1 并尝试此代码;
我不知道您的 Imagick 版本,某些参数可能因版本而异,但它可能会给您的代码带来一些想法。
Use 2>&1 in php shell_exec command and try this code;
I don't know your version of Imagick, some arguments may vary by version, but it might give some idea for your code.
您还有 PHP 中的 imagick 扩展: https://www.php.net /manual/fr/book.imagick.php
You have also an imagick extension in PHP: https://www.php.net/manual/fr/book.imagick.php