Page 1 of 1

complex resize operation

Posted: 2007-12-30T03:12:32-07:00
by -Dan-
Hi Guys.Happy New Year!
I looked around first, but I haven't found something similar, and I was hoping someone could help me out:
I need to resize an image, in a single operation(I need the load on the server to be as low as possible), to several sizes, some of them fixed.
So given an image,I need:
-if the size is >1024x768, make a 1024x768 thumbnail, preserving the aspect ratio
-if the size is >800x600, make a 800x600 thumbnail, also preserving the ratio
-make a fixed size(ignore ratio, but make t centered) for 300x300 and 100x100


I am using PHP, via exec().
I remember an example Anthony posted a while ago, but I simply can't find it!
Thank you so much for your help.

Re: complex resize operation

Posted: 2007-12-30T04:10:11-07:00
by Bonzo
From a previous post by ZootSuitRyan try this:

Code: Select all

<?php
exec("convert input.jpg \( +clone -thumbnail 1024x768> -write image_large.jpg +delete \) \( +clone -thumbnail 800x600> -write image_medium.jpg +delete \)\( +clone -thumbnail 300x300! -write image_small.jpg +delete \)-thumbnail 100x100! image_tiny.jpg");
?>

Re: complex resize operation

Posted: 2007-12-30T08:09:54-07:00
by -Dan-
thank you, but it didn't work.Not as expected, anyway.
I ended up with 2 pics @ 1024, 2 @800, and the 300 and 100 ones were pretty ugly because of the forceful resize.
Is there a way to resize the to fit the box nicely?
yes, I read the /Usage area, but I never got it to work the way I want

Re: complex resize operation

Posted: 2007-12-30T08:22:08-07:00
by -Dan-
also, a stupid little question:
if I want to convert a.png to a.jpg, removing the original a.png after completion, would IM do that?or I have to unlink(a.png) at the end?

Re: complex resize operation

Posted: 2007-12-30T09:08:39-07:00
by Bonzo
That is strange I thought it would have worked; I tried a load more tests but could not get it working:

Creates Large-0, large-1, medium-0, medium-1, small-0, small-1 & tiny
Tiny has large, medium and small written on it so its resizing the previous image.

Code: Select all

<?php
exec("convert 2007_1226christmas0004.jpg \( +clone -thumbnail \"1024x768>\" -pointsize 50 -font Arial -fill rgba\(0,0,0,0.4\) -gravity north -annotate +0+0 \"large\" -write large.jpg +delete \) \( +clone -thumbnail \"800x600>\"  -pointsize 50 -font Arial -fill rgba\(0,0,0,0.4\) -gravity center -annotate +0+0 \"medium\" -write medium.jpg +delete \) \( +clone -thumbnail 300x300! -pointsize 50 -font Arial -fill rgba\(0,0,0,0.4\) -gravity south -annotate +0+0 \"small\" -write small.jpg +delete \) -thumbnail 100x100! tiny.jpg");
?>
Creates Large, medium, small & tiny
Tiny has large, medium and small written on it so its resizing the previous image.

Code: Select all

<?php
exec("convert 2007_1226christmas0004.jpg -thumbnail \"1024x768>\" -pointsize 50 -font Arial -fill rgba\(0,0,0,0.4\) -gravity north -annotate +0+0 \"large\" -write large.jpg -thumbnail \"800x600>\"  -pointsize 50 -font Arial -fill rgba\(0,0,0,0.4\) -gravity center -annotate +0+0 \"medium\" -write medium.jpg -thumbnail 300x300! -pointsize 50 -font Arial -fill rgba\(0,0,0,0.4\) -gravity south -annotate +0+0 \"small\" -write small.jpg -thumbnail 100x100! tiny.jpg");?>
You will have to unlink() any tempory images.

For a better quality image you can use -quality and with your 100x100 image all I can sugest is resize it so the shortest side is 100 and then crop the longest side to 100.

Re: complex resize operation

Posted: 2007-12-30T12:49:56-07:00
by -Dan-
thanks.
got it to work, based on your previous post