Calling convert from PHP, how to get return code?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Calling convert from PHP, how to get return code?

Post by the-ninth »

Hi,

I am calling the convert command line program from PHP with the following command:

exec( $cmd, $output = array(), $return_var );

$cmd has the full command line, e. g.:

/usr/bin/convert "photos_gallery/2010-01-05_Myanmar/RP_2010-01-09_0920_01_thumb.jpg" -write temp/307_thumb_h240.icc -resize x240 -unsharp 1x2+1+0.1 -quality 80 -strip -profile temp/307_thumb_h240.icc "photos_cache/307_thumb_h240.jpg"

Now if something is wrong, then $return_var is always 1, regardless of what error or warning ImageMagick got.

Is there any way to get from PHP the real error/warning code?

My problem is that it seems I get a warning, the $return_val is 1 but the output file is actually there. I'd like to find out what is wrong but I do not have command line access to my hosting server. I also cannot reproduce the issue locally.

Cheers, Robert
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Calling convert from PHP, how to get return code?

Post by Bonzo »

Try:

Code: Select all

$array=array(); 
echo "<pre>"; 
exec("$cmd 2>&1", $array);  
echo "<br>".print_r($array)."<br>";  
echo "</pre>"; 
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Calling convert from PHP, how to get return code?

Post by the-ninth »

Thanks!

Somehow my issue stopped occurring by itself. But next time it happens I'll try that code. :)
Post Reply