Skip to content
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.7.55.2]: setWidth() and setHeight() returning transform setting values, not transformed image values #12023

Closed
garycrane opened this issue Sep 28, 2022 · 3 comments · Fixed by #12046
Assignees

Comments

@garycrane
Copy link

garycrane commented Sep 28, 2022

What happened?

Description

We have a production site running Craft 3.7.42 and a template containing the following code:

<a href="{{ image.getUrl('noCrop2400x2400') }}" class="lightbox-trigger" itemprop="contentUrl" data-size="{{ image.getWidth('noCrop2400x2400') }}x{{ image.getHeight('noCrop2400x2400') }}">

The noCrop2400x2400 transform is set to 'Fit' and I've set the width and height to 2400 each, so that the longest edge doesn't exceed that value.

In Craft 3.7.42, image.getWidth() and image.getHeight() are returning the correct dimensions of the transformed image. However, in the my dev env, I've updated to Craft 3.7.55.2 and now the getWidth and getHeight are returning the values I have set within the image transform (in this case 2400 x 2400). The actual transform itself is working fine.

I should note that it's not doing this consistently. For some images, it is returning the correct values. I can't see a pattern. All I do know is that it's working 100% consistently in Craft 3.7.42 but not in Craft 3.7.55.2.

Any idea what might have changed? or what I might need to do to get it working as expected?

Expected behavior

image.getWidth('transform') and image.getHeight('transform') should return the width and height of the transformed image.

Actual behavior

image.getWidth('transform') and image.getHeight('transform') are returning the width and height of the values within the transform settings in Craft.

Craft CMS version

3.7.55.2

PHP version

8.0.23

Operating system and version

Darwin 21.6.0

Database type and version

MySQL 5.7.39

Image driver and version

Imagick 3.6.0 (ImageMagick 7.1.0-48)

Installed plugins and versions

  • Amazon S3: 1.3.0
  • Element API: 2.8.6.1
  • Formie: 1.6.14
  • Mailgun: 2.0.1
  • Redactor: 2.10.10
  • SEO: 3.4.38
  • String Urldecode: 1.0.0
  • Super Table: 2.7.3
  • Typed link field: 1.0.25
@garycrane garycrane changed the title [3.7.55.2]: setWidth() and setHeight() returning the transform setting values, not transformed image values [3.7.55.2]: setWidth() and setHeight() returning transform setting values, not transformed image values Sep 28, 2022
@KarlBishop
Copy link

I'm seeing same behaviour on 3.7.55.2

Mine is coming from the asset width and height properties after a transform is applied, rather than the getWidth() and getHeight() functions.

My code looks like this:

{% do image.setTransform('logo') %}
<img src="{{ image.url }}" alt="{{ siteName }}" width="{{ image.width }}" height="{{ image.height }}">

And the resulting image is scaled to 375 x 150 (correct aspect ratio) but the <img> tag has its width attribute set to 400 (which is the transform's max-width constraint). So the image appears stretched on the page.

@brandonkelly
Copy link
Member

Thanks for reporting that! We’ve fixed this for the next Craft 3 and 4 releases.

To get the fix early, you can change your craftcms/cms requirement to:

  • Craft 3: v3.x-dev as 3.7.55.3
  • Craft 4: dev-develop as 4.2.5.2

Then run composer update.

@brandonkelly
Copy link
Member

Craft 3.7.56 and 4.2.6 are out with the fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants