Problem/Motivation

Portrait images with exif orientation 6 will have wrong width/height attributes and image appears landscape on image styles.

I'd expect portrait images (with exif orientation) to rendered correctly and using correct width and height attributes.

Screenshot of portrait image appearing landscape on image style:
Screenshot of portrait image appearing landscape

Screenshot of wrong width/height attributes on original image:
Screenshot of wrong width/height attributes

Steps to reproduce

1. Install Drupal 9.2.x with standard install profile: php core/scripts/drupal quick-start standard
2. Add article /node/add/article/ upload image with exif orientation 6 (e.g. https://github.com/recurser/exif-orientation-examples/blob/master/Portra...)
3. Save node, the image appears on landscape, using image style large.
4. On /admin/structure/types/manage/article/display change image field to display Original image, save.
5. Reload the node, the image appears as portrait, but the <img> width and height attributes are flipped.

Proposed resolution

Initial idea

The exif_orientation module code provides a solution by auto-rotating each image when it is uploaded. This works but has some potential downsides: it reduces image quality a little; it may remove EXIF data that the site owner needs, for example a contractual commitment to retain copyright information; it won't help with images that have already been uploaded.

Note to anyone planning to use the module that in September 2024, the module is minimally maintained and and has quite a few open bugs, especially when using D10.3. For example the module doesn't cope with the orientations (see #2914824: Provide flip() method for image handling).

Proposal for improved idea

Instead that we make the fix in the place where the problem is introduced: GDToolkit class. The GD2 library loses EXIF data on many operations. Before doing such an operation, then the Drupal wrapper code should apply auto-orientation.

Perhaps another image toolkit is able to do many operations preserving EXIF data, in which case it won't need the same fix. A site admin may have chosen the other image toolkit exactly because they needed to preserve EXIF copyright statements. Therefore the fix should be specific to the image toolkit wrapper for whatever operations need it in that toolkit.

Remaining tasks

- Patch / MR.

User interface changes

-

API changes

-

Data model changes

-

Release notes snippet

-

Comments

sokru created an issue. See original summary.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

adamps’s picture

Title: Portrait images with exif orientation will have wrong width/height attributes » Images incorrectly oriented because GD toolkit discards EXIF orientation
Priority: Normal » Major
Issue summary: View changes

I updated the IS and title to clarify the cause of the problem - which is entirely different from #2664632: Bugs with images that include image orientation from image EXIF data where the browser lacks support for image orientation.

I added an alternative solution that I believe will work better than the approach taken in EXIF orientation module.

I increased the priority because image upload from various mainstream phones is currently causing rotated images.

kim.pepper’s picture

Component: file system » image.module
adamps’s picture

Status: Active » Closed (duplicate)

I've made some updates to #2664632: Bugs with images that include image orientation from image EXIF data and I feel the 2 issues are actually about the same problem. This IS here has some good explanation and I put a reference back to it from the other IS.