Images incorrectly oriented because GD toolkit discards EXIF orientation

Created on 29 April 2021, over 3 years ago
Updated 30 September 2024, 2 months ago

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 wrong width/height attributes on original image:

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 โœจ Provide flip() method for image handling Needs work ).

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

-

๐Ÿ› Bug report
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component

file system

Created by

๐Ÿ‡ซ๐Ÿ‡ฎFinland sokru

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom adamps

    I updated the IS and title to clarify the cause of the problem - which is entirely different from โœจ Add Auto orientation image effect Needs work 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.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia kim.pepper ๐Ÿ„โ€โ™‚๏ธ๐Ÿ‡ฆ๐Ÿ‡บSydney, Australia
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom adamps

    I've made some updates to โœจ Add Auto orientation image effect Needs work 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.

Production build 0.71.5 2024