A handy little snippet that saves you a lot of work is the ability to quickly generate thumbnails from a source image.
01.
from
PIL
import
Image
02.
03.
filename
=
"/tmp/thumbnail_file.jpg"
04.
05.
# Read the image, resize and save as a temporary file
06.
image
=
Image.open(input_filename)
07.
08.
image.thumbnail([max_width, max_height], Image.ANTIALIAS)
09.
10.
image.save(filename,
"JPEG"
)
Image.ANTIALIAS option is the best for sizing down. See the docs for other resize filters.
One thing to keep in mind is that Image.resize() actually resizes the whole image to fit the given size exactly, without preserving the aspect ratio.