- 🇬🇧United Kingdom adamps
I've just hit the rotated images problem on a site, so I've done some research.
This issue seems to be unclear:
- The problem/motivation is "images uploaded from mobile devices such as iphone appear rotated / upside down in Drupal", which would be a bug.
- The issue title is "Add Auto orientation image effect" which would be a feature.
- The "proposed resolution" suggests that the second item would solve the first, but I believe that it's not really true.....
As far as I can see, in 2024 most browsers do support EXIF orientation. The main reason for the wrong orientation is that Drupal has stripped the EXIF metadata without correcting the orientation. The GD library appears to do this when it applies most image effects.
So analysing the proposed solution:
- In the case of an image style applying the image effect, the orientation effect could fix the bug. The site admin would need to apply the orientation effect first on all image styles. However this seems like bad UI as the admin is being forced to apply an effect that they don't expect to need in order to workaround a bug.
- Another case an image field constraint applying an image effect (most likely
FileImageDimensions
). In this case the correct orientation is lost before the file is ever saved, so there's no possible fix.
So in summary I believe that the "Auto orientation image effect" would be either a poor fix or no fix at all to the problem/motivation.
- 🇬🇧United Kingdom adamps
There is a similar issue #3211441: Portrait images with exif orientation will have wrong width/height attributes → that is less active, but seems much more clear. The title and problem/motivation are consistent, and the proposed resolution is much more heading in the right direction: add exif_orientation module code into core.
I took a quick look and here's a quick summary of what I found:
- The approach taken is to apply auto-orientation immediately when an image is uploaded. This 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.
- The module is minimally maintained and and has quite a few open bugs, especially when using D8.3.
- Even after fixing those, I feel that the code isn't the best approach that we would take in Core, partly inevitably so because Core doesn't expose the necessary hooks.
Still, the module is a good starting point, and it helped point me in the right direction, so thank you to the developers and maintainers.
- 🇬🇧United Kingdom adamps
I propose instead that we make the fix in the place where the problem is introduced: GDToolkit. 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.
- 🇬🇧United Kingdom adamps
Sorry I belatedly see that I have duplicated #8 however that information wasn't in the IS. Hopefully I've helped future readers understand the key point by @mondrake.
- We can add an image effect as a feature and it makes some useful code available.
- However it won't (without further work) solve the bug that EXIF orientation data is already lost on upload.
- Really we'd like the auto-rotate to happen automatically rather than the site admin needing to remember to add it in the UI.
- 🇬🇧United Kingdom adamps
I updated the IS with all my findings. I feel it's a bug not a feature, how feel free to reset if you don't agree.