Image Resize option future

See all posts See thread Reply

Re: Image Resize option future new!
by Cassiano Rabelo, 17 years, 4 months ago
What if I want the image to have always 70px in height by whatever width (keeping the ratio, of course).
This is the code I'm using:

$handle = new Upload('input.jpg');
$handle->file_overwrite  = TRUE;
$handle->file_auto_rename  = FALSE;
$handle->file_safe_name = false;
$handle->image_resize = TRUE;
$handle->image_ratio_no_zoom_in = TRUE;
$handle->image_y = 70;
$handle->file_new_name_body = 'output';
$handle->Process(PATH_IMGS);

I tried this and it works on most of my images, but I have one image with 1130x450 that ends up with 150x59.
One way to fix this is to use a "fake" image_x really huge (12000 for instance), but I dont know if this might have an side effect.
How should this be done? Do I need an "if" to test the sizes first?
Thank you once again for the great class.Reply
Re: Image Resize option future new!
by colin, 17 years, 3 months ago
Yes, it is normal in fact, I can confirm the behaviour.

Here is what happens:
If you use image_ratio_no_zoom_in, then it takes in account image_x and image_y. Since image_x is by default set at 150 pixels, it resizes your picture so that it is not taller than 70 pixels, but also not wider than 150px.

So you have two solutions.

This one, which sets an extra large maximum width:
$handle->image_ratio_no_zoom_in = TRUE;
$handle->image_y = 70;
$handle->image_x = 9999;
Or this one, which calculates the width (but will zoom in if the original height is less than 70px):
$handle->image_ratio_x = TRUE;
$handle->image_y = 70;
Reply