Add Auto orientation image effect

Created on 8 February 2016, almost 9 years ago
Updated 13 February 2024, 12 months ago

Problem/Motivation

images uploaded from mobile devices such as iphone appear rotated / upside down in Drupal

Proposed resolution

include the 'auto orientation' effect, to read the EXIF data in the image for the correct orientation, part of 'Image Effects' (the spiritual successor to imagecache actions from D7):

https://www.drupal.org/project/image_effects

Remaining tasks

User interface changes

API changes

Data model changes

Original report

so...i still see rotated image issues...

we fought this in d7, and hoped for better image orientation detection in d8...

Example:
http://foodtron.org/node/11

What does the wisdom of the group recommend?

Do we need another exif autodetect magic hack module?

this has been an issue for over 4 years...inherited by d8...

It was just a normal photo taken on my iphone 6s...and i remember this all the way back to iphone 3...

same pic on the phone via email comes out fine. attaching original pic to this thread.

@geerlingguy suggests:
The 'auto orientation' effect is part of 'Image Effects' (the spiritual successor to imagecache actions from D7): https://www.drupal.org/project/image_effects

See: https://github.com/drupal-media/image_effects#introduction (it's supported by both GD and ImageMagick).

Looks like it's not in core, though :(

Looks like this ( https://www.drupal.org/node/2284577 ) is the closest thing to possibly making that happen. Outside of the media project, it looks like there's not much interest in doing the work :(

@barrett suggests:
And thus round 5274 of the Small Core vs Expected OOTB Functionality fight is begun....

It seems reasonable to me that whatever system provides image upload and display functionality should also have capability to figure out which way is up in the image.

@mark-trapp suggests:
This tends to happen when taking photos using a mobile device that allows you to access the shutter with a hardware button (like a volume button): iPhones and some (most?) Android phones have this feature.

Here's an article explaining the problem for iPhone (though you can find people confused about it on Android as well): http://iphonephotographyschool.com/iphone-photos-upside-down/

Feature request
Status

Needs work

Version

11.0 🔥

Component
Image system 

Last updated 2 days ago

Created by

🇺🇸United States jacov

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇪🇸Spain candelas

    Hello,

    Any patch for Drupal 11 and 10?
    Thanks

  • 🇬🇧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:

    1. 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.
    2. 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
  • 🇬🇧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.

Production build 0.71.5 2024