tags:

views:

259

answers:

2

hi,

I want to change the resolution of the .bmp image in python. ( i.e. the pixel/inch information) . Using PIL, for jpg image, for instance, the following code works fine

import Image 
im = Image.open("myImg.jpg)
im.save("output.jpg", dpi = (75, 75) )

If you view this in some image editing software like GIMP, it shows the Pixel per inch as 75, 75.

But the above code doesn't work when the input image is a .bmp file.

Could someone tell me how to change image resolution for any image in python?

A: 

Hi, I think input file can be any valid format and output need to be, jpg, pcx, png, tiff, wmf for dpi parameter I think, may be I am wrong, but when I looked at PIL source files, I don't see one for BMP files.

S.Mark
+2  A: 

I suspect that there aren't many programs out there that respect bmp resolution. Windows bitmaps are all 96 dpi.

Also, It looks as though PIL doesn't support a resolution parameter for bitmaps. My PIL/BmpImagePlugin.py just writes in $01000000 for the x & y resolution (i'm not sure what that translates to, but I'd guess "96 dpi").

There are docs which tell you how to write your own extension .. I'd guess it would be pretty simple to make a copy of the PIL bitmap plugin which accepted resolution as a parameter.

Seth
+1 for good explanations
S.Mark
Thanks this is very useful!
apt