Python基础之PIL(pillow)模块实例
pillow模块内容繁杂,因此使用实例展示内容
##1. 安装PIL(windows)
方式一:打开cmd(管理员模式) — 输入“pip install pillow
” — 自动下载安装 ---- 出现 “Successfully installed pillow-5.2.0
”即安装成功
使用pip list
可查看是否安装pillow
C:\Windows\system32>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
asn1crypto (0.24.0)
cffi (1.11.5)
cryptography (2.2.2)
idna (2.7)
Pillow (5.2.0)
pip (9.0.1)
pycparser (2.18)
pygame (1.9.3)
PyMySQL (0.9.2)
setuptools (28.8.0)
six (1.11.0)
##2. 验证码生成实例
from PIL import Image, ImageDraw, ImageFont
import random
# 添加字母
def creatImg(width,height):
# 偏移量x
global x
# 创建新的画布,透明度为完全透明
img = Image.new("RGBA", (width, height), (0, 0, 0, 0