Fix missing EXIF orientation handling#104
Open
cargocultprogramming wants to merge 3 commits into
Open
Conversation
| # source), because ImageOps.exif_transpose() should correct the | ||
| # orientation before saving. | ||
| assert result.size == original.size | ||
|
|
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.