[Image-SIG] saving dpi for png

Tim Arnold Tim.Arnold at sas.com
Wed May 14 17:28:04 CEST 2008


hi,
I found it difficult to discover how to set the dpi for png images with pil, so I'd like to suggest an addition to the documentation:
-------------------------------------------------------------
You can read the metadata in a png file as follows:
im = Image.open('myfile.png')
print im.info
##or just one value, for example:
#print im.info['dpi']

You cannot change the values in the info dictionary directly, but you can set the values by using options on the save method:
im1.save('mynewfile.png','PNG',dpi=(300,300))

You can see the results by opening and reading the info dictionary again:
im2.open('mynewfile.png')
print im2.info['dpi']

---------------------------------------------------------
I'm no expert and there may be a better way to accomplish this, but it got me what I needed.
I think it's a fairly common situation.

thanks,
--Tim Arnold





More information about the Image-SIG mailing list