https://github.com/Show-Me-the-Code/show-me-the-code
第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。类似于图中效果
from PIL import Image, ImageDraw, ImageFont
def add_num(pic_path, num):
img = Image.open(pic_path)
x, y = img.size
font = ImageFont.truetype("/usr/share/fonts/truetype/./ubuntu-font-family/Ubuntu-R.ttf", x/4)
ImageDraw.Draw(img).text((3*x/4, 0), str(num), font=font, fill='red')
img.save('icon_with_num.jpg')
if name == "main":
add_num("icon.jpg", 5)