[magick-users] algorithim to resize images
Eric Holzapfel
ewholz at gmail.com
Mon Jan 29 11:59:10 CST 2007
Hello All,
I am using PHP and imagemagick to resize images and make thumbnails for
a photo web site.
I have decided that I would like to limit the width of a horizontal image to
900 pixels, and the height to 600 pixels (maybe 750px).
I have a bit of code in PHP that calculates the size for the height:
$image_y = round(($orig_y * $image_x) / $orig_x);
here image_x is the max width (900), and orig_x is the width of the actual
image before resize.
My problem comes with vertical images (height > width).
I want the max height to be 700 (maybe 750) and the width should not exceed
the 900 parameter. I can use imagemagick to set the width of an image (1732
wide by 2841 high). I set the width to a percent of the image with a ratio:
1732/2841 : desired width/700 which is: width = 700*1732/2841
(which gives 427) , but then to calc the new height (using imagemagick)
like "convert -resize 427 img.jpg new_img.jpg the new height can exceed my
desired 700 pixels. This example falls within my parameters, but
is there a better way to determine a proportional resize for images?
thanks,
eric
More information about the Magick-users
mailing list