Image Resize option future

See all posts Reply

Image Resize option future new!
by rr1024, 17 years, 4 months ago
This functionality maybe available but I don't know how to use your class yet....Anyway

I was wondering if there is a way to use image resize when and only when the image is larger than X or larger than Y.
Example:
$handle->image_ratio_x   = TRUE;
$handle->image_ratio_y   = TRUE;
$handle->file_max_size = (int)$ImageArr['Size']; // 1024 = 1KB

$handle->image_y       = 300;
$handle->image_x       = 400;

if ( $handle->image_x < $ImageW ) {
     #resize image according to x ratio I think
} elseif ( $handle->image_y < $ImageY ){
     #resize image according to y ratio I think
} else {
     # Do nothing the images is smaller than max limits
}

Basically, it would be nice to have this built into the class I think.....
You supply image max X Y and a resize only occures if the image X is larger than max X or image Y is larger than max Y or image X Y are both larger than max XY...

I hope that makes sence, I'm currently working with your vers 24Reply
Re: Image Resize option future new!
by colin, 17 years, 4 months ago
You will have to use the version 0.25 RC1.

First, you should not have more than one image_ratio_xxxx used together. So your code:
$handle->image_ratio_x = TRUE;
$handle->image_ratio_y = TRUE;
should be:
$handle->image_ratio = TRUE;

To do what you describe, you have two possibilities:

1. Resize only if the picture is larger than the specified sizes, using image_ratio_no_zoom_in
$handle->image_resize = TRUE;
$handle->image_ratio_no_zoom_in = TRUE;
$handle->image_y = 300;
$handle->image_x = 400;

2. Otherwise, you can set un maximum number of pixels, using image_ratio_pixels. So the image will be resized to approximate this maximum number of pixels.
$handle->image_resize = TRUE;
$handle->image_ratio_pixels = 120000; //300x400
Reply
Re: Image Resize option future new!
by rr1024, 17 years, 4 months ago
Is version 25 compatible with version 24Reply
Re: Image Resize option future new!
by colin, 17 years, 4 months ago
Yes, it should be 100% backward compatible. In fact, just some marginal effects (background color for transparent images) might differ, but that is because 0.24 was buggy, and 0.25 fixes these bugs, and a large part of the image processing has been rewritten.

0.25 is Release Candidate only, so there might be issues. This said, it has been out for two weeks now, and so far there are no new bugs found, nor any reports of incompatibilities.

Upgrade to 0.25 will be encouraged; upgrade to 0.25 RC1 is suggested. I will release the proper 0.25 in one week or two.Reply
Re: Image Resize option future new!
by rr1024, 17 years, 4 months ago
I'll let you know if I find anything ....nice class dude and Nice Documentation job!
Are you using phpDocumenter script?Reply
Re: Image Resize option future new!
by colin, 17 years, 4 months ago
Yes, I am using PHPDocumentor, with some post-editing.

Speaking of which, I plan to add to this site a more comprehensive documentation, set of examples, etc... as well as a configuration generator. Hopefully, I will have time to complete this for the 0.25 release...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, 4 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