Skip to content

Commit ee69f1e

Browse files
author
chen2aaron
committed
add chen2aaron
1 parent 94a3172 commit ee69f1e

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

chen2aaron/0000/4number.png

423 KB
Loading

chen2aaron/0000/img.png

511 KB
Loading

chen2aaron/0000/img.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
# Created by xixijun
4+
# Date: 15-5-13
5+
# Blog: morningchen.com
6+
7+
8+
from PIL import Image
9+
from PIL import ImageDraw
10+
from PIL import ImageFont
11+
12+
13+
class AddNumToPic(object):
14+
15+
"""
16+
第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,
17+
类似于微信未读信息数量那种提示效果。 类似于图中效果
18+
"""
19+
def __init__(self):
20+
self.font = None
21+
self.img = None
22+
23+
def open(self, img_path):
24+
self.img = Image.open(img_path)
25+
return True
26+
27+
def set_font(self, font_path, size):
28+
self.font = ImageFont.truetype(font_path, size)
29+
return True
30+
31+
def draw_text(self, str, color, ttf):
32+
xSize, ySize = self.img.size
33+
fontSize = min(xSize, ySize) // 11
34+
position = (0.9 * xSize, 0.1 * ySize - fontSize)
35+
draw = ImageDraw.Draw(self.img)
36+
draw.text(position, str, fill=color, font=ttf)
37+
self.img.show()
38+
self.img.save(str + "number" + '.png')
39+
return True
40+
41+
if __name__ == '__main__':
42+
pic = AddNumToPic()
43+
pic.open('img.png')
44+
pic.set_font('microsoft_yahei.TTF', 80)
45+
pic.draw_text('4', 'red', pic.font)

chen2aaron/0000/microsoft_yahei.TTF

14.3 MB
Binary file not shown.

chen2aaron/creat_file.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
# Created by xixijun
4+
# Date: 15-5-13
5+
# Blog: morningchen.com
6+
7+
import os
8+
9+
10+
def creat_file(path):
11+
"""
12+
在指定目录创建子文件夹 0000~0025
13+
"""
14+
for i in range(26):
15+
n = str(i).zfill(4)
16+
sub_path = path + n
17+
os.mkdir(sub_path)
18+
return path
19+
20+
if __name__ == '__main__':
21+
path = "/Users/chan/python/chen2aaron/"
22+
creat_file(path)

0 commit comments

Comments
 (0)