Is it possible to change a picture resolution with Python?

Lad python at hope.cz
Thu Sep 21 03:21:30 EDT 2006


Tim Roberts wrote:
> "Lad" <python at hope.cz> wrote:
>
> >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,
> >Thank you for your reply.
> >But the above code increases size only , but not DPI resolutions(
> >vertical nad horizontal).I need  a higher  vertical and horisontal
> >resolutions.
>
> I'm not convinced that you know what you are asking for.
>
> Let's say you have an image that is 300x300 pixels, that is tagged as being
> 100 dpi.  Such an image is expected to be printed at a 3" x 3" size.
>
> Now, if you want to increase the dpi to 300 dpi, what does that mean?  Does
> it mean you want that same picture to be printed at a 1" x 1" size?  If so,
> then all you need to change is the picture header.  It will still be
> 300x300 pixels, and the file will be the same number of bytes.
>
> Or, do you mean that you want the picture to continue to print as 3" x 3",
> but to have three times as many pixels in each direction?  That means you
> have to increase the number of pixels to 900x900.  That's exactly what the
> code above is doing.  The image file will be 9 times larger.

Tim ,
Thank you for the explanation,
And I must also thank you all you others, who helped me.
Particularly,  bearophile and Max.

Now I use the following code , that provided bearophile,

from PIL import Image
im = Image.open("output3.jpg")
nx, ny = im.size
im2 = im.resize((int(nx*2.5), int(ny*2.5)), Image.BICUBIC)
im2.save("2000.png",dpi=(520,520))


and very important thing was dpi=(520,520) that provided Max,
L.




More information about the Python-list mailing list