美文网首页
github/Show me the code (0)

github/Show me the code (0)

作者: 知识分子中的文盲 | 来源:发表于2016-05-06 23:27 被阅读24次

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)

相关文章

网友评论

      本文标题:github/Show me the code (0)

      本文链接:https://www.haomeiwen.com/subject/ymmjrttx.html