Floren
Well-known member
Hi guys,
I need some help with the cropping logic for specific images. Basically, I want the image to be exactly 1024x576px. For the width, I can do this easy with the thumbnail() function but my goal is to actually crop the image after to exactly 576px.
Thinking out loud:
If an user uploads a 1300x2000px image, the thumbnail() function will fix the width to 1024px and crop() with adjust the image height proportionally to 576px. Any better methods or suggestions are welcome.
Thank you for your help.
I need some help with the cropping logic for specific images. Basically, I want the image to be exactly 1024x576px. For the width, I can do this easy with the thumbnail() function but my goal is to actually crop the image after to exactly 576px.
Thinking out loud:
Code:
$dimensions = array(
'width' => 1024,
'height' => 576
);
$image->thumbnail($dimensions['width']);
$ratio = ($image->getWidth() / $image->getHeight());
if ($ratio > ($dimensions['width'] / $dimensions['height']))
{
// crop top and bottom only, to 576px
}
Thank you for your help.
Last edited: