You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that for some jpeg images Pillow does not report correct DPI.
For instance, I created with Gimp a PNG file of size 1x1 pixels with resolution of 123 dpi (test2.png) and then I converted it with imagemagick to test2.jpg. The command was:
I attach both files (zipped, as images.zip). When I use Pillow to read dpi of test2.jpg, this is what I get:
$ ipython3
In [1]: from PIL import Image
In [2]: print(Image.__version__)
10.4.0
In [3]: Image.open('test2.jpg').info
Out[3]: {'jfif': 257, 'jfif_version': (1, 1), 'jfif_unit': 2, 'jfif_density': (48, 48)}
I see that jfif_density and jfif_unit pair is correct (48 px/cm is 123 px/in), but I think that this info structure should also contain 'dpi' entry - and it does not contain it. For instance, when I create a similar jpeg file directly from Gimp (test3.jpg, also attached), it works as I want:
$ ipython3
/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py:935: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.8.10 (default, Nov 7 2024, 13:10:47)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from PIL import Image
In [2]: print(Image.__version__)
10.4.0
In [3]: Image.open('test3.jpg').info
Out[3]:
{'jfif': 257,
'jfif_version': (1, 1),
'dpi': (123, 123),
'jfif_unit': 1,
'jfif_density': (123, 123),
'exif': b'Exif\x00\x00II*\x00\x08\x00\x00\x00\x07\x00\x0e\x01\x02\x00\x12\x00\x00\x00b\x00\x00\x00\x1a\x01\x05\x00\x01\x00\x00\x00t\x00\x00\x00\x1b\x01\x05\x00\x01\x00\x00\x00|\x00\x00\x00(\x01\x03\x00\x01\x00\x00\x00\x02\x00\x00\x001\x01\x02\x00\r\x00\x00\x00\x84\x00\x00\x002\x01\x02\x00\x14\x00\x00\x00\x92\x00\x00\x00i\x87\x04\x00\x01\x00\x00\x00\xa6\x00\x00\x00\x00\x00\x00\x00Created with GIMP\x00{\x00\x00\x00\x01\x00\x00\x00{\x00\x00\x00\x01\x00\x00\x00GIMP 2.10.18\x00\x002024:12:28 07:13:34\x00\x02\x00\x86\x92\x07\x00\x19\x00\x00\x00\xc4\x00\x00\x00\x01\xa0\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Created with GIMP\x00',
'progressive': 1,
'progression': 1}
The text was updated successfully, but these errors were encountered:
So your request is that when the JFIF unit is 2, meaning that the JFIF density is per cm, then info["dpi"] should be inferred from that? That seems reasonable. I've created #8633
Yes, you summarized the problem better than me - the problem is "what should be the value of DPI if JFIF unit is 2".
The whole thing have started when I noticed today that img2pdf (which uses Pillow) do not support correctly files in which JFIF unit is 2 (see: josch/img2pdf#40 ). So now some code needs to support this scenario - either img2pdf or Pillow itself. And probably it's better if Pillow takes care of it.
It seems that for some jpeg images Pillow does not report correct DPI.
For instance, I created with Gimp a PNG file of size 1x1 pixels with resolution of 123 dpi (test2.png) and then I converted it with imagemagick to test2.jpg. The command was:
I attach both files (zipped, as images.zip). When I use Pillow to read dpi of test2.jpg, this is what I get:
I see that jfif_density and jfif_unit pair is correct (48 px/cm is 123 px/in), but I think that this info structure should also contain 'dpi' entry - and it does not contain it. For instance, when I create a similar jpeg file directly from Gimp (test3.jpg, also attached), it works as I want:
The text was updated successfully, but these errors were encountered: