[Image-SIG] question about DPI

Alec Bennett wrybread at gmail.com
Tue May 12 05:11:06 CEST 2009


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) )
canvas.paste(im1, (0, 0), im1 )

im2 = Image.open("test2.jpg").convert('RGBA')
im2 = im2.resize ( (800, 600) )
canvas.paste(im2, (900, 0), im2 )

canvas.save("output.jpg", quality=100, dpi = (300, 300))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090511/3381293d/attachment.htm>


More information about the Image-SIG mailing list