DPI

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DPI

Samuel Moore-3

I am trying to determine DPI from images. Can anyone help?

I tried:

 

img = Image.open(“Hamerkop.jpg”)

img.info[“dpi”]

 

but it doesn’t work for all jpegs.

 

Python 2.5.1

PIL 1.1.7

 

Regards,

Sam


_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: DPI

Edward Cannon
I find that the info object often does not have the exact key you are looking for, many different encoders use slightly different variants, or don't include it at all. My best advice is to print out the info for several of your files and look for patterns. Also there are some tools for working more directly with EXIF data, these might also be useful. Unfortunately this area is not really standard, so every solution is likely to break down sometimes.
Edward Cannon

On Fri, Apr 16, 2010 at 5:48 AM, Samuel Moore <[hidden email]> wrote:

I am trying to determine DPI from images. Can anyone help?

I tried:

 

img = Image.open(“Hamerkop.jpg”)

img.info[“dpi”]

 

but it doesn’t work for all jpegs.

 

Python 2.5.1

PIL 1.1.7

 

Regards,

Sam


_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig



_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: DPI

Fredrik Lundh
In reply to this post by Samuel Moore-3
Resolution info is optional in JPEG files (it's a part of the JFIF
standard, not JPEG itself) and even if present, it may not be
expressed in dots per inch.  PIL only sets the "dpi" field if the
information is there, leaving it to your code to provide a suitable
default value (or behaviour) for your application.  You can do e.g.

    dpi = im.info.get("dpi", (72, 72))

If the JFIF header is present, but the resolution isn't specified as
DPI, you can check if the "jfif_unit" and "jfif_density" fields
contain information useful for your application; their contents are
described here:

http://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#JFIF_segment_format

</F>

On Fri, Apr 16, 2010 at 2:48 PM, Samuel Moore <[hidden email]> wrote:

> I am trying to determine DPI from images. Can anyone help?
>
> I tried:
>
>
>
> img = Image.open(“Hamerkop.jpg”)
>
> img.info[“dpi”]
>
>
>
> but it doesn’t work for all jpegs.
>
>
>
> Python 2.5.1
>
> PIL 1.1.7
>
>
>
> Regards,
>
> Sam
>
> _______________________________________________
> Image-SIG maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/image-sig
>
>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig