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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:29:02  来源:igfitidea点击:

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

pythonpython-imaging-librarypillow

提问by wolfgang

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

我想在枕头 python 中调整图像大小,但是我有两个功能可供选择:

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

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

and

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

Image.thumbnailhttp://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.resizeresizes to the dimensions you specify:

Image.resize调整到您指定的尺寸:

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

Image.thumbnailresizes 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 thumbnailresizes it in place, whereas resizereturns the resized image.

此外,调用thumbnail会就地调整大小,而resize返回调整大小的图像。