[Image-SIG] question about DPI

Fredrik Lundh fredrik at pythonware.com
Tue May 12 14:39:18 CEST 2009


On Tue, May 12, 2009 at 5:11 AM, Alec Bennett <wrybread at gmail.com> wrote:
> I'm pasting a few images onto a canvas, resizing them, and saving the canvas
> in 300 dpi. The idea that even though I'm resizing those pictures, I'd like
> to preserve as much of their data as possible. In other words I'd like them
> to be very high quality.
>
> I'm not sure I'm doing this correctly, however. I think I'm losing a lot of
> quality in the resizing stage. Can anyone see room for improvement in my
> code?
>
> If it matters, the pictures that I'm pasting in are from a digital camera.
>
> Here's the stripped down relevant bits:
>
> import Image
>
> canvas = Image.new("RGBA", (1800, 1200), "black" ) # 6"x4" printed
>
> im1 = Image.open("test1.jpg").convert('RGBA') # this would be larger than
> 3000 pixels wide, very large
> im1 = im1.resize ( (800, 600) )

Try:

im1 = im1.resize ( (800, 600), Image.ANTIALIAS )

or, more efficient if the source image is a lot larger than the result:

im1.thumbnail ( (800, 600), Image.ANTIALIAS )

(when used directly after open, the latter tells the JPEG decoder to
downsample during decoding, and then updates the image in place).

</F>


More information about the Image-SIG mailing list