【高级特性】52、图像处理库(PIL)【高级特性】52、图像处理库(PIL)
目录
一、Pillow库
二、图像处理步骤
三、PIL图像操作
四、小程序:PIL生成验证码
一、Pillow库
- Python里的图像处理库
PIL:Python Image Library - 功能强大,可以对图像做各种处理
缩放、裁剪、旋转、滤镜、文字、调色板等等
二、图像处理步骤
- 打开图像
image.open()
Pillow库能自动根据文件内容确定格式
若图片在程序目录下,则不需要附带路径,直接将图像名+文件格式作为参数 - 处理图像
image模块中提供了大量处理图像的方法 - 存取或显示图像
im.show()
im.save()
三、PIL图像操作
缩略图
- thumbnail函数
thumbnail(size,Image.ANTIALIAS)
参数size为一个元组,指定生成缩略图的大小
直接对内存中的原图进行了修改,但是修改完后的图片需要保存,处理后的图片不会被拉伸
模糊效果

image.png

image.png
添加文字

image.png

image.png
四、小程序:PIL生成验证码

image.png

image.png

image.png
微信赞赏
支付宝赞赏