简体   繁体   English

与PHP一起使用时,Imagemagick convert命令返回错误代码4

[英]Imagemagick convert command returning error code 4 when used with PHP

I am executing ImageMagick command using PHP exec function, it returns an error code 4 which probably mean The system cannot open the file when however I run same command in Windows terminal it works fine. 我正在使用PHP exec函数执行ImageMagick命令,它返回error code 4 ,这probably意味着当我在Windows终端中运行相同的命令时The system cannot open the file ,但工作正常。 I am using this below command to resize the image: 我正在使用以下命令来调整图像大小:

In terminal(working fine) 在终端(工作正常)

convert -resize 150^% ad.png res_ad.png

In PHP (returning error code 4) 在PHP中(返回错误代码4)

exec(escapeshellcmd("convert -resize 150% $file_name.png res_$file_name.png"), $output2, $return2)

PS: I have checked and path of the image is correct. PS:我已经检查过,图像路径正确。

I have only had a 1 or 0 returned from Imagemagick using php so I do not know were the 4 is coming from. 我只有1或0使用php从Imagemagick返回,所以我不知道4是从那里来的。

I have used similar code to yours but have never used escapeshellcmd in the exec. 我使用了与您相似的代码,但是从未在exec中使用过escapeshellcmd。 The exec is calling an external program and I am not sure you can use it there. 该执行程序正在调用一个外部程序,但我不确定您是否可以在其中使用它。

Try( notice the input image comes right after the convert in most cases ): 尝试(注意,在大多数情况下,输入图像紧随转换之后):

exec("convert $file_name.png -resize 150% res_$file_name.png");

You can validate your input and output image filenames before sending them to exec() 您可以先验证输入和输出图像的文件名,然后再将它们发送到exec()

Different error reporting: 不同的错误报告:

$array=array();
echo "<pre>";
exec("convert $file_name.png -resize 150% res_$file_name.png 2>&1", $array); 
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM