Reputation: 651
I'm running the following Imagemagick command on many images. Some images fail, but I'm not sure why... how can I get a detailed error message or error number from ImageMagick with PHP to help with troubleshooting the failures?
$myexec = 'convert -trim -density 200 /path/filename.tif -resize 70% /path/filename.png';
exec($myexec, $output, $return);
if (!$return) {
//success
}else{
//failed
}
Upvotes: 0
Views: 582
Reputation: 53164
In ImageMagick, you should read the input first (assuming it is a raster image and not a vector image), then settings, then operators that use those setting, then other settings. Also you should specify -units. PNG only supports density and units of pixelspercentimeter. But if you specify units of pixelsperinch, ImageMagick will automatically convert the density to a value in pixelspercentimeter that corresponds to the corresponding pixelsperinch. To see any textual error messages, try the following:
$myexec = "convert /path/filename.tif -trim -resize 70% -units pixelsperinch -density 200 /path/filename.png 2>&1";
exec($myexec, $output, $return);
foreach($output as $text) {echo "$text<br>";}
You might also want to specify a -fuzz XX% before -trim if the background is not perfectly uniform. XX is a value between 0.0 and 100.0
Upvotes: 1