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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With