1、实现代码
from PIL import Image
im = Image.open('pic_in.png')
x,y = im.size
try:
# 使用白色来填充背景
# (alpha band as paste mask).
p = Image.new('RGBA', im.size, (255,0,255))
p.paste(im, (0, 0, x, y), im)
p.save('pic_out.png')
except:
pass
2、安装PIL
因为现在PIL已经没有维护,可以直接安装pillow
#更新pip
python -m pip install --upgrade pip
#安装pillow
pip install pillow