第 0000 题: 将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 类似于图中效果
# -*- coding: utf-8 -*-
from PIL import Image,ImageFont,ImageDraw,ImageColor
def add_num(image,text):
#1.打开图片
#2.设置字体
font = ImageFont.truetype("arial.ttf",50)
#3.设置字体颜色
fontcolor = ImageColor.colormap.get('red')
#4.将字体加到图片上
draw = ImageDraw.Draw(image)
width , height = image.size
draw.text((width-50,30),text,font=font,fill=fontcolor)
#5.保存图片
image.save("D:\\image2.jpg")
if __name__ == '__main__':
image = Image.open('D:\\thumbnail.jpg')
text = "4"
add_num(image,text)