Imagemagick command line not working

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
daniel
Posts: 3
Joined: 2013-08-09T04:51:40-07:00
Authentication code: 6789

Imagemagick command line not working

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Imagemagick command line not working

Post 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.
snibgo's IM pages: im.snibgo.com
daniel
Posts: 3
Joined: 2013-08-09T04:51:40-07:00
Authentication code: 6789

Re: Imagemagick command line not working

Post 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?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Imagemagick command line not working

Post by glennrp »

You can use "/path/to/convert" or just "convert" but not both.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Imagemagick command line not working

Post 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
daniel
Posts: 3
Joined: 2013-08-09T04:51:40-07:00
Authentication code: 6789

Re: Imagemagick command line not working

Post by daniel »

thanks guys that did it. It now works perfectly thanks again
Post Reply