Skip to content

BUG: Apply EXIF orientation in x2pdf - #313

Open
jayhemnani9910 wants to merge 1 commit into
py-pdf:mainfrom
jayhemnani9910:fix/x2pdf-exif-orientation
Open

jayhemnani9910 wants to merge 1 commit into
py-pdf:mainfrom
jayhemnani9910:fix/x2pdf-exif-orientation

Conversation

@jayhemnani9910

Copy link
Copy Markdown

pdfly x2pdf puts portrait phone photos into the PDF sideways. Phones save a portrait shot as landscape pixels plus an EXIF Orientation tag (6 = rotate 90° clockwise), and every image viewer shows it upright. With a 400x300 JPEG tagged Orientation=6:

pdfly x2pdf phone.jpg plain.jpg -o x.pdf
pdfinfo -f 1 -l 1 x.pdf   # Page 1 size: 400 x 300 pts, expected 300 x 400

image_to_pdf (pdfly/x2pdf.py:21-27) takes the page size from the raw pixels and passes the file to FPDF.image(), and neither applies the tag. This transposes the image with ImageOps.exif_transpose when 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_orientation fails for rotate-90 before 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/A

  • A mention of the change is present in CHANGELOG.md N/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.

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

No deployments
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