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
-