Python 中最流行的图像处理库
Pillow 是 Python Imaging Library(PIL)的一个活跃分支,提供了广泛的文件格式支持、高效的内部表示以及强大的图像处理能力。 它是 Python 开发者进行图像读取、修改、保存和分析的首选工具。
使用 pip 即可轻松安装:
pip install Pillow
支持 JPEG、PNG、BMP、GIF 等数十种格式。
旋转、缩放、裁剪、翻转等几何操作。
模糊、锐化、边缘检测、色彩调整等。
在图像上绘制文字、线条、形状等。
from PIL import Image
img = Image.open('example.jpg')
img.show()
from PIL import Image
img = Image.open('example.jpg')
resized_img = img.resize((300, 200))
resized_img.save('resized.jpg')
from PIL import Image, ImageFilter
img = Image.open('example.jpg')
blurred = img.filter(ImageFilter.BLUR)
blurred.save('blurred.jpg')
from PIL import Image, ImageDraw, ImageFont
img = Image.open('example.jpg')
draw = ImageDraw.Draw(img)
font = ImageFont.load_default()
draw.text((10, 10), "Hello PIL!", fill="white", font=font)
img.save('with_text.jpg')
78TP文档:https://pillow.readthedocs.io/
GitHub 仓库:https://github.com/python-pillow/Pillow