Page 1 of 1

using php, achiving multiple imaageMagick tasks in 1 exec()

Posted: 2008-01-11T22:29:22-07:00
by cssEXp
I searched and experimented but to no solution.

first scenario - the following is executed, works great.

Code: Select all

    exec("convert -resize {$width}x{$width} $mImage -quality 75 $tImage");
second scenario - if certain other option such as file info etc. are requested, the following takes place in addition to above mentioned.

Code: Select all

    exec("convert -size {$info_width}x{$info_height} xc:black $tImage -gravity north -geometry +0+1 -composite -quality 75 $tImage");
    exec("convert +size $tImage -pointsize $ifontsize -font \"$ifont\" -fill \"$irgba\" -gravity south -annotate +0+1 \"$itext\" -quality 75 $tImage");
in second scenario it goes through 2 image file saves before its again saved for the last time, so many quality differences occur from the first scenario. So What I'd like to know is, if it's possible to implement the following 3 exec's into 1 exce with only 1 image save.

Code: Select all

    exec("convert -resize {$width}x{$width} $mImage -quality 75 $tImage");
    exec("convert -size {$info_width}x{$info_height} xc:black $tImage -gravity north -geometry +0+1 -composite -quality 75 $tImage");
    exec("convert +size $tImage -pointsize $ifontsize -font \"$ifont\" -fill \"$irgba\" -gravity south -annotate +0+1 \"$itext\" -quality 75 $tImage");
Thanks in advance.

Re: using php, achiving multiple imaageMagick tasks in 1 exec()

Posted: 2008-01-12T11:28:18-07:00
by Bonzo
This should work:

Code: Select all

<?php

$mImage = '2007_1226christmas0004.JPG';

$width="200";
$height="200";

$info_width = $width;
$info_height = $height + 24;

$tImage='test.png';

$ifontsize = '20';

$itext = "Test";

$irgba="white";

$ifont="verdana.ttf";

exec("convert -size {$info_width}x{$info_height} xc:black -pointsize $ifontsize -font $ifont -fill $irgba -gravity south -annotate +0+1 \"$itext\" \( $mImage -resize {$width}x{$width} \) -gravity north -geometry +0+1 -composite -quality 75 $tImage");
	
?>
This will do the same thing:

Code: Select all

<?php 
exec("montage -geometry +0+0 -background black  -pointsize $ifontsize -font $ifont -fill $irgba  -label \"$itext\" \( $mImage -resize {$width}x{$width} \)  test1.png"); 
?>  

Re: using php, achiving multiple imaageMagick tasks in 1 exec()

Posted: 2008-01-13T00:29:58-07:00
by cssEXp
thanks

Re: using php, achiving multiple imaageMagick tasks in 1 exec()

Posted: 2008-01-13T17:02:07-07:00
by anthony
cssEXp wrote:I searched and experimented but to no solution.

first scenario - the following is executed, works great.

Code: Select all

    exec("convert -resize {$width}x{$width} $mImage -quality 75 $tImage");
You should read the image BEFORE trying to resize it. The above works due to some legagy code, but will start to go wrong as soon as you try to add more than one operation.


For handling multiple operations in a single "convert" command. you can process an image, then specifically -write the result. At that point you can -delete the image from memory and start a completely ne process. You may have to reset previously used settings, so caution is needed.

For example (I'll leave of the exec("...") part)

Code: Select all

convert \
    image1.png -resize 200x200 -write image1_200.png   +delete \
    image2.png -resize  100x100 -write image2_100.png +delete \
    image3.png -frame 10x10 -rite image3_framed.png +delete \
    null:
The final "null:" just tels IM to junk any left over images (there are none so it prevents an error cause by attempting to write zero images).
As you can see an image is read in, modified, written out, and deleted, before the next image is processed.

You do NOT have to delete old images if you use parenthesis. this means previous images are still in memory, and can be 'cloned' for later processing.

For more information see. IM Examples Basics, Image sequence Operators
http://imagemagick.org/Usage/basics/#image_seq
Especially the Debugging Usage Example, at the end of that section (after 'cloning' and just before attributes) - sorry no direct link.
Also Writing an image Multiple Times
http://imagemagick.org/Usage/files/#write

Re: using php, achiving multiple imaageMagick tasks in 1 exec()

Posted: 2008-01-18T21:45:42-07:00
by cssEXp
i can't seem to understand your example when you use filemane i don't have in my code, it tends to confuse me, i.e which is which. I'm talking about image1_200.png, image2_100.png, image1.png, image2.png, image3.png. in my code i only have two image name, the save path and the source path, please clarify.

Moreover I'm having problem with the code Bonzo gave, one with montage, actually it woks great a 81 kb with 800x600 pixels file resized to 150 width and according height width 75 quality is around 6 kb. The problem is normal resize.

i'm also creating normal thumbnail for those that don't want to label it width words.

exec("convert -resize 150x $imagepath -quality 75 $saveto");

here the quality is almost same but the file size is around 12kb, which is twice the one made with montage. Any solution please? :)

Re: using php, achiving multiple imaageMagick tasks in 1 exec()

Posted: 2008-01-19T01:40:16-07:00
by Bonzo
If you use -resize add -strip to remove all EXIF data etc.

Code: Select all

exec("convert $imagepath -strip -resize 150x -quality 75 $saveto");
-thumbnail does it automaticaly.

Code: Select all

exec("convert $imagepath -thumbnail 150x -quality 75 $saveto");
Also notice the image is the first thing after convert.

Re: using php, achiving multiple imaageMagick tasks in 1 exec()

Posted: 2008-01-23T23:48:22-07:00
by anthony
I think then we all need to take a step back....

What do you exactly mean by... multiple Image Magick tasks.

Multiple image processing in a single command. Multiple operations? Generating multiple images, combining multiple images into one image, what? Answer that (prehaps in a new tread, with a new subject) and we may be able to help you properly.

describe what you want, before, and after all the operations are done.