Skip to content

Conversation

@radarhere
Copy link
Member

Resolves #8632

Pillow uses JFIF density to set info["dpi"], but only when the JFIF unit is 1, meaning that the JFIF density is per inch.

if jfif_unit == 1:
self.info["dpi"] = jfif_density
self.info["jfif_unit"] = jfif_unit
self.info["jfif_density"] = jfif_density

This PR updates it so that when the JFIF unit is 2, meaning that the density is per cm, the density is converted to be per inch and used to set info["dpi"].

See page 11 of https://www.ecma-international.org/wp-content/uploads/ECMA_TR-98_1st_edition_june_2009.pdf for the relevant specification.

For the test image, I copied the existing test image multiple_exif.jpg, and manually modified the file to have a different JFIF unit, and also to set the X and Y density to be different to allow for better testing.

@radarhere radarhere added the JPEG label Dec 28, 2024
@hugovk hugovk merged commit 743256f into python-pillow:main Dec 29, 2024
49 checks passed
@radarhere radarhere deleted the jfif_unit branch December 29, 2024 21:59
@radarhere radarhere mentioned this pull request Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PIL does not recognize dpi of some jpeg images

2 participants