Repository navigation
BUG: Apply EXIF orientation in x2pdf - #313
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
Phone cameras save portrait photos as landscape pixels with an EXIF Orientation tag. x2pdf sized the page from the raw pixels and embedded the file as is, so those photos came out sideways. Transpose the image when the tag asks for a rotation; other images are still embedded from the file unchanged. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
pdfly x2pdfputs portrait phone photos into the PDF sideways. Phones save a portrait shot as landscape pixels plus an EXIFOrientationtag (6 = rotate 90° clockwise), and every image viewer shows it upright. With a 400x300 JPEG taggedOrientation=6:image_to_pdf(pdfly/x2pdf.py:21-27) takes the page size from the raw pixels and passes the file toFPDF.image(), and neither applies the tag. This transposes the image withImageOps.exif_transposewhen the tag asks for a rotation and sizes the page from the result. Images without a rotation are still embedded from the file as before, so they aren't re-encoded.Tested on main 7c77387 (pypdf 7.1.0, fpdf2 2.9.0): the new parametrized test
test_x2pdf_applies_exif_orientationfails forrotate-90before the change and passes after; full suite 242 -> 245 passed; ruff, ruff format and mypy clean. With the change the command above gives a 300 x 400 page 1 with the photo upright, and page 2 (plain JPEG) is unchanged.Checklist:
A unit test is covering the code added / modified by this PR
In case of a new feature, docstrings have been added, with also some documentation in the
docs/folder N/AA mention of the change is present in
CHANGELOG.mdN/A (written at release)This PR is ready to be merged
By submitting this pull request, I confirm that my contribution is made under the terms of the BSD 3-Clause license.