Pillow-Python中Image.resize和Image.thumbnail有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29367990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between Image.resize and Image.thumbnail in Pillow-Python
提问by wolfgang
I want to resize an image in pillow-python, however I have 2 functions of choice to use:
我想在枕头 python 中调整图像大小,但是我有两个功能可供选择:
Image.resize
http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.resize
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
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?
两个定义都指出要调整图像大小,我应该使用哪一个?
回答by wolfgang
Image.resize
resizes to the dimensions you specify:
Image.resize
调整到您指定的尺寸:
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
调整到最大尺寸,(a) 保留纵横比,(b) 不超过原始图像,(c) 不超过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.
此外,调用thumbnail
会就地调整大小,而resize
返回调整大小的图像。