Repository navigation
fix(image): apply the EXIF orientation when loading image frames - #4247
Merged
PeterStaar-IBM merged 1 commit intoSep 16, 2026
Merged
Conversation
A camera stores the sensor readout plus an orientation tag rather than rotated pixels, so a portrait photo reached OCR and layout on its side: a 200x100 JPEG tagged orientation 6 came out 200x100 and unrotated instead of 100x200. ImageOps.exif_transpose swaps the pixel dimensions but leaves info["dpi"] alone, so the DPI axes are swapped whenever it actually rotated the frame; without that a square 72x72 pt page reads as 36x144. Signed-off-by: kakiuwang-ui <[email protected]>
Contributor
|
✅ DCO Check Passed Thanks @kakiuwang-ui, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
cau-git
approved these changes
Sep 16, 2026
This was referenced Nov 8, 2026
PeterStaar-IBM
pushed a commit
that referenced
this pull request
Nov 9, 2026
A camera stores the sensor readout and an EXIF orientation tag rather than rotated pixels, and browsers show an <img> turned by that tag. The shared ImageResourceLoader and the MHTML branch of the HTML backend ignored it, so a portrait photo in an HTML, MHTML, Markdown, AsciiDoc, JATS or EPUB document became a sideways picture with its width and height swapped. The image backend already applies the tag (#4247). Apply ImageOps.exif_transpose after the image is decoded in both places. Signed-off-by: Mohammad Sohail Shaikh <[email protected]>
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 camera stores the sensor readout plus an EXIF orientation tag rather than
rotated pixels.
ImageDocumentBackendnever read that tag, so a portrait photoreached OCR and layout on its side:
The page image handed downstream is sideways too, so OCR reads a rotated line,
layout scores a rotated block, and the page image in the exported document is
rotated for the reader.
Implementation
_oriented_framerunsImageOps.exif_transposeon each frame and returns itwith its DPI axes.
exif_transposeswaps the pixel dimensions for the quarter-turn orientationsbut leaves
info["dpi"]alone, so the axes are swapped here as well; withoutthat, a 300x150 frame at 300x150 dpi — a square 72x72 pt page — reads as
36x144 after the rotation.
The swap keys off the frame actually changing size rather than off the tag
value. Pillow's TIFF plugin already applies the orientation while opening, so
exif_transposeis a no-op there; keying off the tag would swap the DPI axes asecond time for those files.
Test
Two cases in
tests/test_backend_image_native.py, both on a JPEG with a blackmarker in the top-left corner:
test_exif_orientation_rotates_the_frame— the page is 100x200 and themarker has moved to the top-right.
test_exif_orientation_swaps_dpi_axes— the physical page stays 72x72 pt.Checked by breaking each part: dropping the transpose fails both, and keeping
the transpose while dropping the DPI swap fails only the second.
make validateis clean and the file's other 25 tests still pass.
Notes for review
quarter-turn tag. The transpose leaves the size unchanged, so the DPI axes are
not swapped. Keying off the tag instead would fix that case and break the TIFF
one above; happy to handle both explicitly if you would rather.
same shape as the recent
fix(webvtt)andfix(epub)changes.Checklist: