Resizing images before upload when using BulletProof upload class
Asked Answered
T

1

13

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.

Twobit answered 8/9, 2014 at 22:46 Comment(1)
I got the solution in C# do you want it so you can translate it ? shouldn't be too difficult.Woodborer
B
2

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)
Burdine answered 10/12, 2014 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.