简体   繁体   中英

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. 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)

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.

I have only had a 1 or 0 returned from Imagemagick using php so I do not know were the 4 is coming from.

I have used similar code to yours but have never used escapeshellcmd in the exec. 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()

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>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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