Populate JPEG DPI from JFIF cm density by radarhere · Pull Request #8633 · python-pillow/Pillow
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.