第 0000 题: 将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。
from PIL import Image,ImageFont,ImageDraw,ImageColor
def add_num(imagePath,text):
# 1.打开图片
image = Image.open(imagePath)
draw = ImageDraw.Draw(image) # 创建draw对象
width, height = image.size # 获取尺寸
# 2.设置字体
font = ImageFont.truetype("arial.ttf",size=100) # 字体与大小
fillcolor = "#ff0000" # 设置颜色
# 3.将字体加到图片上
draw.text((width-100,30),text,font=font,fill=fillcolor)
# 5.保存图片
image.save('0.jpg')
if __name__ == '__main__':
imagePath = 'pic.jpg' # 源图片路径
text = '7' # 书写内容
add_num(imagePath,text)