Resize - max only

See all posts Reply

Resize - max only new!
by Tim, 17 years, 6 months ago
I want to resize an image so that its max width/height is 500px, but the user's image is already smaller than that.

If I do this, it will stretch the smaller image out to have a width or height of 500:

$handle->image_resize = true;
$handle->image_ratio	= true;
$handle->image_x = 500;
$handle->image_y = 500;

I don't want any image to get stretched. If it's smaller than image_x or _y, I want it to stay smaller.Reply
Re: Resize - max only new!
by seanie, 17 years, 6 months ago
This bit resizes if its x is over 600
Check out php.net for more info on getimagesize()
$info = getimagesize($handle->file_src_pathname);
if ($info[0]>600) {
    // resize
} else {
    // dont resize
}
Reply
Re: Resize - max only new!
by colin, 17 years, 6 months ago
Thanks Seanie, your code is correct, however there is a better way to do it: the class provides a parameter called image_ratio_no_zoom_in

From the doc:
image_ratio_no_zoom_in same as image_ratio, but won't resize if the source image is smaller than image_x x image_y (default: false)

So Tim, if you want to resize images that are bigger than 500px, but keep it as is if it is smaller, use the following code:
$handle->image_resize = true;
$handle->image_ratio_no_zoom_in	= true;
$handle->image_x = 500;
$handle->image_y = 500;
Reply