getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.5k stars 1.4k forks source link

cropZoom() image upscaling #2342

Open dani-ooo opened 5 years ago

dani-ooo commented 5 years ago

is there a way to prevent cropZoom() from upscaling images? is this the expected behavior?

if i have an image that's 1200×800, and i pass it through cropZoom(2000,900), it is upscaled with the new proportion. i want the image to be crop-zoomed to the new aspect ratio, but not bigger than the original dimensions. cropResize() already behaves this way.

dani-ooo commented 5 years ago

i think derivatives() has a conditional to avoid this — maybe it could be added to cropZoom() as well? https://github.com/getgrav/grav/blob/f1363877d8782fbceb4dd53d38d538f57b7104de/system/src/Grav/Common/Page/Medium/ImageMedium.php#L279-L280

dani-ooo commented 5 years ago

for now, i've come up with a workaround — using the min() between the image's width and height as the cropZoom() parameters:

{{ image.cropZoom(min(image.width, image.height), min(image.width, image.height)) }}