What is the difference between Image.resize and Image.thumbnail in Pillow-Python

wolfgang picture wolfgang · Mar 31, 2015 · Viewed 25.1k times · Source

I want to resize an image in pillow-python, however I have 2 functions of choice to use:

Image.resize http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.resize

and

Image.thumbnail http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.thumbnail

Both definitions point out to resizing the image, Which one should I be using?

Answer

wolfgang picture wolfgang · Mar 31, 2015

Image.resize resizes to the dimensions you specify:

Image.resize([256,512],PIL.Image.ANTIALIAS) # resizes to 256x512 exactly

Image.thumbnail resizes to the largest size that (a) preserves the aspect ratio, (b) does not exceed the original image, and (c) does not exceed the size specified in the arguments of thumbnail.

Image.thumbnail([256, 512],PIL.Image.ANTIALIAS) # resizes 512x512 to 256x256

Furthermore, calling thumbnail resizes it in place, whereas resize returns the resized image.