Search code examples
phpimage-scaling

php upload class & smart resizing


I am using this class on my PHP project to resize pictures: http://www.verot.net/php_class_upload_docs.htm

What I am trying to achieve now is to have some sort of 'smart resize'; let me explain.

Right now, I use the following code in order to resize the image.

$handle->image_resize         = true;
$handle->image_ratio_crop     = true;
$handle->image_x              = 600;
$handle->image_y              = 400;

This way, even if the image is very wide or very tall, it will just crop the exceeding parts. What I am trying to do is basically resizing to maximum values of X and Y so that in cases of long or wide pictures, all the class will do is just scaling them pixel by pixel so that there will be no need to crop exceeding or use filling.

This can be sort of achieved by simply setting image_x without image_y or vice versa, but it will not work for all the above cited cases.

Any idea on how to work this out?

Thanks in advance.


Solution

  • Include the class given here. Then use

    $resizeObj -> resizeImage(240 ,135 , 'auto');
    $resizeObj -> saveImage('sample-resized.jpg', 100);