Is it possible to change a picture resolution with Python?

Tim Roberts timr at probo.com
Sat Sep 23 06:32:40 CEST 2006


"Lad" <python at hope.cz> wrote:
>
>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,

I'm glad that you achieved your goal, but I don't think we have quite made
our point yet.  I want to make sure this is clear, in case you need to do
this again.

The dpi=(520,520) is NOT the "very important thing".  The only thing that
does is change the number in the header.  It doesn't change the image at
all.  The "very important thing" in this script is the "im.resize", which
smoothly stretches the image so that it has 2.5 times as many pixels as
before.  It is that stretching which allows you to change the DPI in the
header, and yet still have it print at the same size.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list