pyhton PIL制作圆形头像
参考转载:
https://www.dazhuanlan.com/langwirter/topics/1462147
https://www.jianshu.com/p/cdea3ba63cd7
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
import random
color = [random.randint(0, 255),random.randint(0, 255),random.randint(0, 255)]
bg = Image.new('RGB', (100, 100), (color[0],color[1],color[2])) # 背景图
box = (0,0,100,100)
bgqq = Image.open('./qq.png')
mask = Image.new('RGBA', (100, 100), color=(0,0,0,0))
mask_draw = ImageDraw.Draw(mask) # 在这个蒙板上画的
mask_draw.ellipse((0,0, 100,100), fill=(0,0,0,255))
bg.paste(bgs, box, mask)
bg.show()
效果如图??