[Image-SIG] PIL DPI trouble - Solved
bloominator at hotmail.com
Fri Sep 21 21:28:57 CEST 2007
Thanks for shedding some light on this topic. However, what you've said has
left me even more curious than before. There are still some things I don't
For one, why do Photoshop (PS) and Paint Shop Pro (PSP) play so nicely
together when the PIL doesn't play along at all for DPI. If I create an
image with certain DPI in Photoshop, Paint Shop Pro can read the image and
see that set density, and vice versa. But the PIL doesn't recognize the DPI
of either a PSP or Photoshop image. And of course neither PS or PSP
recognize the DPI of a PIL image. So I'm a bit confused. You say that PIL
seems to be "playing by the rules" and adhering to the JFIF standard. (My
images are both TIFF and JPEG, but I'm guessing that it's the same problem
regardless of which image type it is.), yet PSP and PS cannot read the DPI
of these PIL-processed images. This doesn't make sense to me. If, what you
say below is true and PSP and PS are adding "extra stuff" outside of the
JFIF standard, is it coincidental that they can understand one another?
And, even if they are both writing (and reading the other's) non-standard
DPI info, shouldn't the PIL be foresighted enough to have a "compatibility
mode"' for that "extra stuff"? Sometimes just adhering blindly to a
standard is a good thing, unless the rest of the world is ignoring the
standard, which is what it seems PSP and PS are doing. So do you have any
idea how to make the PIL compatible with these other programs? At work my
company has a product which also deals with images, and one day I imported
an image that I had resized and changed the DPI of it via the PIL, and it
made our software crash. This has never happened when using any other
program to manipulate images. Any thoughts on this? Or perhaps can you
point me to someone who can shed even more light on the matter?
Thanks so much for your reply,
----- Original Message -----
From: "Luca De Santis" <lucadex at gmail.com>
To: <Image-SIG at python.org>
Cc: <bloominator at hotmail.com>
Sent: Friday, September 21, 2007 6:12 AM
Subject: PIL DPI trouble - Solved
>I found out that the behaviour of PIL was totally correct and simply
> Photoshop "adds" some more information sometimes when a JPEG file is
> I summarize what I discovered here, hoping it might be useful to others.
> The JPEG standard doesn't cover a way to encode the resolution of a
> file but the JFIF extension does. For a quick and useful introduction
> to these concepts you can visit the Wikipedia page
> Here you can find a very useful table with the byte map of a JFIF file.
> In particular the "Density Units" field is a byte with three possible
> * 0 - No units, aspect ratio only specified
> * 1 - Pixels per Inch
> * 2 - Pixels per Centimetre
> With a value of Density Units == 1 or == 2 you can get the resolution
> information in the next two fields (2 bytes long each), that is "X
> Density" and "Y Density". Of course these map exactly "dpi" when
> Density Units == 1.
> For all the images that I opened with PIL and couldn't find the dpi
> attribute I "hex-dumped" them and found out the following values for
> these fields:
> * Density Unit: 0
> * X Density: 1
> * Y Density: 1
> I assume that in these cases Photoshop simply sets the resolution to
> the default for screens (which is 72 dpi at least on the Mac).
> Correctly PIL doesn't set the dpi attribute in the "info" dictionary.
> To cut this long story short... I was wrong and PIL rocks hard! :-)
> Hope my experience could help others.
> Luca De Santis
> Pisa, Italy
> On 9/17/07, Luca De Santis <lucadex at gmail.com> wrote:
>> That's exactly the same problem I incurred into.
>> I tried PIL version 1.1.6 on a Mac OS X 10.4 and on an old Linux box
>> and can't get the DPI attribute for JPEG and PNG files that I've
>> created with Photoshop.
>> I tested that both on Python 2.5 and Python 2.1.3 with the same result.
>> I tried also to update libjpeg on Linux but nothing changes.
>> Any help on that is greatly appreciated.
More information about the Image-SIG