Is it possible to change a picture resolution with Python?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Sep 20 11:39:30 EDT 2006


Lad:
> Is it possible to change a picture resolution with Python?
> Let's say I have a picture with a resolution of 96 dpi and I would like
> to increase to 256dpi or higher.

"Resolution" is a too much overloaded word, from some point of view
increasing the resolution of images is a very difficult thing, that may
need deblurring, etc. So let's talk in a simpler way, about the len of
the sides of the image measured in pixels.
To increase such len, you can use PIL library, the resize method from
image:
http://www.pythonware.com/library/pil/handbook/image.htm

This is some example code:

from PIL import Image
im = Image.open("1.jpg")
nx, ny = im.size
im2 = im.resize((int(nx*1.5), int(ny*1.5)), Image.BICUBIC)
im2.save("2.png")

Bye,
bearophile




More information about the Python-list mailing list