Pillow-Python中Image.resize和Image.thumbnail有什么区别 [英] What is the difference between Image.resize and Image.thumbnail in Pillow-Python

查看:370
本文介绍了Pillow-Python中Image.resize和Image.thumbnail有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在枕头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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆