Python第三方图像处理库Pillow学习笔记

编程 · 05-08 · 260 人浏览
Python第三方图像处理库Pillow学习笔记

之前介绍过利用Python实现图片翻转图片裁剪图片拼接,使用的第三方库是matplotlib,今天来学习另一个用于图像处理的第三方库Pillow。

python.webp

Pillow

PIL( Python Imaging Library)是一个Python第三方图像处理库,由于其功能丰富,API简洁易用,因此深受好评,是Python中最常用且最受欢迎的图像处理库之一。

但是,PIL库更新缓慢。于是一群Python社区志愿者在PIL库的基础上开发了一个支持Python3版本的图像处理库,它就是Pillow。

安装

安装Pillow:pip install Pillow,pip下载速度慢的话,可通过修改pip镜像源加快模块下载速度

使用

文件hello.py:

import sys
from PIL import Image

images = []
for arg in sys.argv[1:]:
    images.append(Image.open(arg))

images[0].save(
    "merged.gif", save_all=True, append_images=images[1:], duration=200, loop=0
)

命令行运行:python hello.py 1.gif 2.gif

Python
Theme Jasmine by Kent Liao