fix: handle EXIF orientation for uploaded images#11362
Merged
cdrini merged 8 commits intointernetarchive:masterfrom Oct 29, 2025
Merged
fix: handle EXIF orientation for uploaded images#11362cdrini merged 8 commits intointernetarchive:masterfrom
cdrini merged 8 commits intointernetarchive:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where author photos uploaded from Wikimedia Commons were displaying rotated 90° counterclockwise by implementing EXIF orientation handling.
- Added EXIF orientation correction using PIL's
ImageOps.exif_transpose()method - Integrated orientation handling into the image processing pipeline before thumbnail generation
- Included proper error handling with fallback to original image
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Contributor
Author
|
PTAL @RayBB, thanks. |
Removed apply_exif_orientation function and integrated its logic directly into save_image.
cdrini
approved these changes
Oct 29, 2025
Collaborator
cdrini
left a comment
There was a problem hiding this comment.
Lgtm, thank you @akramcodez ! @RayBB tested with the sample image and with an image that doesn't need rotation.
Modified the code a bit to make this inline, since it's not a piece we'll likely need in another method.
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.

Closes #11129
Description
Author photos uploaded from Wikimedia Commons were appearing rotated 90° counterclockwise.
This fix adds EXIF orientation handling to automatically correct image rotation before saving thumbnails.
Changes
Added
apply_exif_orientation()function toopenlibrary/coverstore/coverlib.pyusing PIL'sImageOps.exif_transpose()method.This function is called in
write_image()immediately after opening the image and before thumbnail generation.It automatically reads EXIF orientation metadata, rotates the image pixels accordingly, and removes the EXIF tag to prevent future rotation issues.
The solution handles all 8 EXIF orientation values and includes proper error handling with fallback to the original image.
Screen Recording
exif-video.mov