Skip to content

Commit 34edbed

Browse files
committed
完成第一题
1 parent 3c58e97 commit 34edbed

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎chris5641/0000/arial.ttf‎

894 KB
Binary file not shown.

‎chris5641/0000/img.png‎

316 KB
Loading

‎chris5641/0000/img.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。
4+
"""
5+
from PIL import Image, ImageFont, ImageDraw
6+
7+
__author__ = 'Chris5641'
8+
9+
10+
def img_add_num(num=1):
11+
img = Image.open('img.png')
12+
w, h = img.size
13+
font = ImageFont.truetype('arial.ttf', w // 4)
14+
draw = ImageDraw.Draw(img)
15+
draw.text((w*3//4, 0), str(num), font=font, fill='red')
16+
img.save('img2.png')
17+
18+
19+
if __name__ == '__main__':
20+
img_add_num(5)

0 commit comments

Comments
 (0)