阅读(4524) (0)

Pillow Image模块实例

2021-07-12 15:51:38 更新

打开、旋转和显示图像(使用默认查看器)

下面的脚本加载图像,将其旋转45度,并使用外部查看器(通常是UNIX上的xv,以及Windows上的paint程序)显示它。

from PIL import Image
im = Image.open("bride.jpg")
im.rotate(45).show()

创建缩略图

下面的脚本创建当前目录中所有JPEG图像的漂亮缩略图,保留最大分辨率为128x128的纵横比。

from PIL import Image
import glob, os

size = 128, 128

for infile in glob.glob("*.jpg"):
    file, ext = os.path.splitext(infile)
    im = Image.open(infile)
    im.thumbnail(size)
    im.save(file + ".thumbnail", "JPEG")