Page 1 of 1

Imagemagick command line not working

Posted: 2013-08-09T05:00:02-07:00
by daniel
Hi All

Im new to ImageMagick and just trying to get it working through command line. I did it once so I know it works but then changed the code without saving the page (Silly me!!) and now its no longer working.

Here is my code

Code: Select all


$imgDir = "/images/icons"; 
$IMGMGK = "/usr/bin/convert"; 
$command = "convert $imgDir/lantech_logo_lge.jpg -resize 64x64 $imgDir/lantech_logo_lge.jpg";
passthru("\"$IMGMGK\" $command", $returnVal);

if ($returnVal > 1) {echo "ERROR";} 
else {echo "<img src=\"$imgDir/lantech_logo_lge.jpg\">";} 


 
The image goes through the command fine and then displays but the image has not be been resized, its just displaying the original image. If I try to find out my version I get this....

Version: ImageMagick 6.8.3-6 2013-03-15 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC Features: DPC OpenMP Modules Delegates: bzlib fontconfig freetype gslib jng jp2 jpeg lcms pango png ps rsvg tiff wmf x xml zlib

Re: Imagemagick command line not working

Posted: 2013-08-09T06:10:25-07:00
by snibgo
The IM command looks okay.

I'm no PHP expert, but the first parameter to passthru looks wrong. It will expand to:

Code: Select all

/usr/bin/convert convert /images/icons/lantech_logo_lge.jpg {...}
I think the first parameter should be a valid comand, and this isn't.

Re: Imagemagick command line not working

Posted: 2013-08-09T07:59:03-07:00
by daniel
Ive now checked and my passthru command will echo to this....

"/usr/bin/convert" convert /images/icons/lantech_logo_lge.jpg -resize 100x100 /images/icons/lantech_logo_lge.jpg


The instructions for imageMagick found http://www.imagemagick.org/Usage/basics/#cmdline say the format should be

convert input.jpg -function output.jpg

As far as I understand before this I also need the path to ImageMagick in "/usr/bin/convert" infront of the convert function. Is this not correct?

Re: Imagemagick command line not working

Posted: 2013-08-09T08:09:07-07:00
by glennrp
You can use "/path/to/convert" or just "convert" but not both.

Re: Imagemagick command line not working

Posted: 2013-08-09T10:47:17-07:00
by Bonzo
This is how I would write your code:

Code: Select all

$imgDir = "/images/icons"; 
$IMGMGK = "/usr/bin/convert";
$input = $imgDir . '/lantech_logo_lge.jpg';
$output = $imgDir . '/lantech_logo_lge.jpg';
$command = "$input -resize 64x64 $output";
// echo $command .'<br>';
exec("$IMGMGK $command", $returnVal);

if ($returnVal > 1) {echo "ERROR";} 
else {echo "<img src=\"$imgDir/lantech_logo_lge.jpg\">";} 
In a lot of cases you can just use convert and not /usr/bin/convert

Re: Imagemagick command line not working

Posted: 2013-08-12T02:58:13-07:00
by daniel
thanks guys that did it. It now works perfectly thanks again