Skip to content

Fix missing EXIF orientation handling#104

Open
cargocultprogramming wants to merge 3 commits into
pelican-plugins:mainfrom
cargocultprogramming:fix-exif-orientation
Open

Fix missing EXIF orientation handling#104
cargocultprogramming wants to merge 3 commits into
pelican-plugins:mainfrom
cargocultprogramming:fix-exif-orientation

Conversation

@cargocultprogramming

Copy link
Copy Markdown
Contributor

A lot of (mobile) photos include EXIF orientation tags. This PR lets Image Process handle the EXIF orientation, by a) rotating the image according to the EXIF orientation and deleting the tag (handled by PIL) and b) preventing the tag from being written into EXIF data again, if these are copied to converted images.

Without this fix, images that carry an EXIF orientation tag are stripped of all tags as per default behavior, resulting in images that are displayed with a wrong orientation in the browser.

The fix is relatively simple, I basically just call the PIL function that handles this case.

I added a test (including two new test images; rotated from existing test images) and made sure it fails before implementing the fix. The test was actually more complicated than the fix, since i had to account for jpeg artifacts, introduced by the image rotation. However all things considered, it's also pretty straight forward.

An alternative fix might be to add an option to copy only the orientation tag of an image (even when not copying other EXIF data) and let the browser handle the rest. However that would be surprising and a change from existing behavior, more complex to implement and depends on the browser's capability to read EXIF and adjust the orientation --> too complex overall.

# source), because ImageOps.exif_transpose() should correct the
# orientation before saving.
assert result.size == original.size

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the size assert is sufficient, the assert following this could be skipped, which would avoid the additional imports. Weaker test, but less imports. Just affects testing though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant