-
Notifications
You must be signed in to change notification settings - Fork 642
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
[3.x]: Image dimension calculation is buggy when upscaleImages is set to false #11837
Comments
Fixes an issue where the height of a non-cropped image being transformed was being calculated as a percentage of the height rather than of the width. #11837
Fixes an issue where the height of a non-cropped image being transformed was being calculated as a percentage of the height rather than of the width. #11837 Fixes an issue where the height of a non-cropped image being transformed was being calculated as a percentage of the height rather than of the width. #11837
Thanks for reporting! That's been fixed for the next Craft 3 and 4 releases. To get the fix early, change your |
I see 3.7.53.1 was released, but the release notes don't mention this fix; did it make it in? |
That version number is a little confusing because |
Craft 3.7.54 and 4.2.4 are now tagged with that fix. |
I'm still seeing incorrect calculations after updating, although at least the aspect ratio of the width and height is correct. Source image: 1080×594px (which is just a smidge wider than 16:9) The code: {% set aspectRatio = 16/9 %}
{% set width = 1280 %}
{% set height = width / (aspectRatio) %}
{% do imgAsset.setTransform({ width: width, height: height }) %}
{{ tag('img', {
src: imgAsset.url(),
width: imgAsset.width(),
height: imgAsset.height(),
}) }} Resulting image dimensions: 1056×594px ( = 16:9 with no upscaling) Resulting code (+ linebreaks for formatting): <img
src="https://example.com/images/_1280x720_crop_center-center_none/MyImage.jpg"
width="1080" height="608"> 1080×608px is 16:9, but it's the wrong 16:9. ;) I'd expect the |
Sure thing; I'll do that in about 12 hours or so. ;) |
Ok, it looks like that fixed the problem I reported, but it may have broken something else. This code is now triggering an error: {% set image = entry.imageField.one() %}
{% set thumb = {
mode: 'crop',
width: min(1440, image.width),
height: 'auto'
} %}
{# The next line triggers the error; it works without `thumb`, eg `image.width()`. #}
{{ image.width(thumb) }}
{# This line is also affected #}
{{ image.height(thumb) }} The cause of the error seems to be when The error I get:
|
@proimage The We’ve just made the code defensive for it though, so if possible it will catch those values and replace them with |
Ahh, of course! 🤦♂️ I got so tangled up in the weeds with this that I didn't take a step back and think if As far as the real bug, it seems tenacious, or perhaps this is another bug that snuck into the patches. {# imgAsset is a 3600×2400 file #}
{% set transform = {
width: 1280,
height: 720
} %}
{% do imgAsset.setTransform(transform) %}
{{ tag('img', {
src: imgAsset.url,
width: imgAsset.width,
height: imgAsset.height
}) }} The output is an <img
src="/path/to/images/_1280x720_crop_center-center_none/MyImage.jpg"
width="3600" height="2025"> It's worth noting that if I alter the transform to omit either the width or the height, the output works as expected: {# imgAsset is a 3600×2400 file #}
{% set transform = {
width: 1280
} %}
{% do imgAsset.setTransform(transform) %}
{{ tag('img', {
src: imgAsset.url,
width: imgAsset.width,
height: imgAsset.height
}) }} <img
src="/path/to/images/_1280xAUTO_crop_center-center_none/MyImage.jpg"
width="1280" height="854"> Since the bug seems to only happen when both a width and a height are specified, would this be a good time or a bad time to dredge up #5288? 😉 |
@proimage Thanks! That’s been fixed as well now. |
@brandonkelly Hooray! That latest patch seems to have finally resolved all the situations I was encountering. Thanks for persevering with me on this—I really appreciate you all. :) |
Thanks for all the help! Craft 3.7.55 and 4.2.5 are out with those fixes. |
What happened?
Description
Given an image Asset of 1080x594, which smaller than a defined transform size, the calculated dimension values are inconsistent and unexpected if the
upscaleImages
config setting isfalse
.Steps to reproduce
config/general.php
, add'upscaleImages' => false,
Expected behavior
I'd expect the resulting image to have the same aspect ratio as 1280x720 (16:9), which it does, and I'd expect the
width="..."
andheight="..."
attributes to reflect the resulting image dimensions (line-breaks added):Actual behavior
The output image is 1056x594px (🎉), but the attributes are
width="1080" height="334"
(🤪) (line-breaks added):Related to
#5288
Craft CMS version
3.7.43
PHP version
7.4.30
Operating system and version
Linux 5.10.102.1-microsoft-standard-WSL2
Database type and version
MySQL 8.0.26
Image driver and version
Imagick 3.6.0 (ImageMagick 6.9.11-60)
Installed plugins and versions
The text was updated successfully, but these errors were encountered: