Wrong crop is saved when image styles use "Automatically correct orientation" effect from the Image Effects module

Created on 13 June 2025, about 2 months ago

Problem/Motivation

1. install image_widget_crop and set up a freeform crop type
2. Make sure that the "Thumbnail" and "Medium" image styles use this "Manual crop"
3. Make sure that the article image field is displayed in "Medium" image style
4. make sure that the article image field should use the "ImageWidget Crop"
5. install https://www.drupal.org/project/image_effects β†’
6. add "Automatically correct orientation" effect as the 1st effect to all the image styles, in that enable "Scan image file"
7. in an article node upload "Portrait_8.jpg" from this (that has EXIF Orientation: left-bottom (8))
8. select the person on the image for cropping:

9. click save and on the node page you can see that a different cloudy part of the image was cropped than what we set:

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

3.0

Component

User interface

Created by

πŸ‡ΈπŸ‡°Slovakia kaszarobert

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kaszarobert
  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    I attach a possible patch with a workaround: where we get the current image width and height, we also check the EXIF Orientation metadata, so if we need to rotate the original image, then we also get the proper width and height.

    When we did the patch, our solution required to work with both GD and ImageMagick image processing libraries + with s3fs module and Amazon S3/Google Cloud Storage file systems, so that's why in the patch we're introducing a dependency to the file_mdm module for checking the needed metadata from image files (which is also a dependency for image_effects) as there's no other built-in way in PHP that works with all of these integrations.

    There's also the src/Plugin/Field/FieldWidget/ImageCropWidget.php getFileImageVariables() function that I did not modify because it was never called by any module. Or do we need to apply this proper width-height checking there, too?

  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    It turns out when using s3fs + using the "Automatically correct orientation" effect means that on an uncached page it will download all the image files from s3fs storage to get its Orientation EXIF metadata during the page load which adds several seconds to TTFB. I guess using the "Automatically correct orientation" effect can't be a scalable solution, we should fix the original image's Orientation instead of doing all these hoops during page load and image style derivative generating manually.

Production build 0.71.5 2024