What is the difference between Image.resize and Im

2019-01-24 00:47发布

问题:

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?

回答1:

Image.resize resizes to the dimensions you specify,

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

Image.thumbnail resizes the the max input dimensions (width and height)

Image.thumbnail([512,512],PIL.Image.ANTIALIAS)

[512,512] are the max dimensions provided for the image resize

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