New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image transforms have option not to 'scale up' #844
Comments
We may add this, but in the meantime, to prevent a transform from scaling the image beyond its size, you can set the target width/height dynamically: {% set transform = {
width: min(150, image.width),
height: min(100, image.height)
} %}
<img src="{{ image.getUrl(transform) }}"> |
Ooooooh, I've never seen this dynamic setting of target width/height before! Very clever :) |
I like Brandon's snipplet, but still a "noUpscale" Option would be great! +1 |
+1 for this feature request. Image resizing in other CMS we've used automatically leaves images alone unless they are too large and actually need resizing & that's exactly what we need in 99% of cases. Thanks. |
Hi brandon, I'am all for a config setting: "upscaleImageTransforms" => false, or something similar. |
@outline4 You could fetch it via getTransformByHandle(): {% set contentWidth = craft.app.assetTransforms.getTransformByHandle('contentWidth') %}
{% set transform = {
width: min(contentWidth.width, image.width),
height: min(contentWidth.height, image.height)
} %} |
After talking this through, we’ve realized there is no good justification for the current behavior of upscaling smaller images to match the crop constraints. And since there are back-end and web performance benefits to not upscaling images, we think it would be better to simply change the behavior so smaller images are never upscaled, rather than making it something you have to opt into. That will potentially cause some layout issues wherever transformed images are getting displayed without |
Also, for images that are smaller than one/both of the crop constraints, we will ensure that the resulting transform has the same ratio as the crop constraints (per #5288).
|
Just a clarification for anyone confused by this like I just was... if upscaling is turned off, and you try to transform an image to a size larger than native, the transformed result will still be stored in the named subdirectory for that transform. So transforming a 400x400px image in |
If a user uploads an image that is smaller than the image transform setting, it scales the image up for them to the specified size. However this results in a pixellated image because of the upscale.
What I would like to be able to do is only scale down images to the respective transform values, but if smaller, then keep their size, thus avoiding the pixellation and extra unnecessary file size.
The text was updated successfully, but these errors were encountered: