github/Show me the code (0)

weixin_34249678發表於2016-05-06

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)

相關文章