Skip to content

Conversation

@dziket
Copy link

@dziket dziket commented Dec 28, 2024

For some JPEG files - for instance some produced by imagemagick - PIL does not return correct DPI, even though DPI is there, in files' headers. For such files img2pdf does not get their DPI, so it assumes it is 96. It causes that when generated PDF is displayed on a screen, pages' sizes are wrong.

To reproduce the problem, generate PDF from
these two JPEG files. When I do it with command:

$ python3 src/img2pdf.py page-1.jpg page-2.jpg -o output.pdf

it produces a PDF file with two pages and when the PDF is displayed on a screen, the sizes of the pages are different. Which is wrong: the dimensions of the two files measured in pixels are different, but they have different DPI, so their dimensions measured in centimeters should be the same.

I already reported a problem to Pillow, but until they fix it, the change in this pull request fixes the problem.

@dziket
Copy link
Author

dziket commented Dec 28, 2024

Hm, probably this change is not needed, because Pillow library is going to fix it:
python-pillow/Pillow#8633

@josch
Copy link
Owner

josch commented Mar 26, 2025

Hi,
I can add your change to cater for older versions of PIL. But even with this being fixed in Pillow 11.1.0, this PR needs a new unit test which creates an image with this property to test that it really does what it is supposed to do. The unit test should break without your changes to src/img2pdf.py and succeed with the changes.

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.

2 participants