这篇文章主要介绍了python Pillow图像处理方法汇总,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Pillow中文文档:https://pillow-cn.readthedocs.io/zh_CN/latest/handbook/tutorial.html
安装:pip install pillow
操作图像:
#!/usr/bin/env python3 # _*_ coding utf-8 _*_ __author__ = 'nxz' from PIL import Image, ImageFilter from time import sleep # 打开一个jpg图像文件 im = Image.open('test.jpg') w, h = im.size # print('图片的宽:%s,和高:%s' % (w, h)) # 图片缩放 im.thumbnail((w // 2, h // 2)) w, h = im.size print(w, h) # 缩放之后的图片重新保存 im.save('thumbnail.jpg', 'jpeg') # 其他功能:切片、旋转、滤镜、输出文字、调色板 # 模糊效果 im2 = im.filter(ImageFilter.BLUR) im2.save('blur.jpg','jpeg')