开发者

changing image resolution in Python for a .bmp file

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 li开发者_StackOverflow社区ke 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜