Pillow-Python中Image.resize和Image.thumbnail有什么区别 [英] What is the difference between Image.resize and Image.thumbnail in Pillow-Python
问题描述
我想在枕头Python中调整图像大小,但是我有2种可供选择的功能可供使用:
I want to resize an image in pillow-python, however I have 2 functions of choice to use:
Image.resize
http://pillow.readthedocs.org/zh_CN/latest/reference/Image.html#PIL.Image.Image.resize
和
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?
推荐答案
Image.resize
调整为您指定的尺寸:
Image.resize
resizes to the dimensions you specify:
Image.resize([256,512],PIL.Image.ANTIALIAS) # resizes to 256x512 exactly
Image.thumbnail
调整为以下最大尺寸:(a)保留宽高比,(b)不超过原始图像,并且(c)不超过thumbnail
参数中指定的尺寸.>
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
此外,调用thumbnail
会调整其大小,而resize
返回已调整大小的图像.
Furthermore, calling thumbnail
resizes it in place, whereas resize
returns the resized image.
这篇关于Pillow-Python中Image.resize和Image.thumbnail有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!