Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing images before upload when using BulletProof upload class

found this which is nice and quick to implement. It works great but what I want it before the images are uploaded, that they get resized to a max width but keeping the ratio.

Let say i am uploading an image with a width of 5000px, i want this to be resized to 1000px width but keep the height ratio and then save the final image.

Example usage:

/* shrink() - will shrink/resize the image according to the given dimensions (in pixels) 
 * NOTE, a folder called 'shrinked_images' will be created first to store the uploaded image
 */ 
$bulletProof
->fileTypes(array("jpg", "gif", "png", "jpeg"))
->uploadDir("shrinked_images")
->shrink(array("height"=>100, "width"=>200))
->upload($_FILES["pictures"]);

The GitHub:

https://github.com/samayo/bulletproof

I have read through the docs but cant find anything about resizing. All i can find in the code is the shrinking function but cant see how to add the keep ratio option with that?

Thanks. Craig.

like image 407
Lovelock Avatar asked Sep 08 '14 22:09

Lovelock


1 Answers

Second parameter of shrink is $ratio which allows to preserve aspect ratio.

Try

->shrink(array("height"=>100, "width"=>200), true)

or if you want your images resized using width only set height to PHP_INT_MAX as both parameters are required

->shrink(array("height"=> PHP_INT_MAX, "width"=>200), true)
like image 174
mleko Avatar answered Nov 11 '22 05:11

mleko