Skip to content

Commit 80c14bb

Browse files
committed
Merge pull request Show-Me-the-Code#68 from Raynxxx/master
Finish problem 0000
2 parents 89593aa + bfe3dd8 commit 80c14bb

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Raynxxx/0000/ex00.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
__author__ = 'rayn'
2+
3+
#problem 0000
4+
#Add a unread number on the face icon
5+
6+
from PIL import Image
7+
from PIL import ImageFont
8+
from PIL import ImageDraw
9+
10+
class UnreadTagFace:
11+
def __init__(self):
12+
self.img = None
13+
self.num = None
14+
def open(self, image_path):
15+
self.img = Image.open(image_path)
16+
return True
17+
def draw(self, tag_num = 1):
18+
tag_size = max(self.img.size[0], self.img.size[1]) / 5
19+
tag_str = str(tag_num) if tag_num < 100 else '99+'
20+
font = ImageFont.truetype("Arial.ttf", tag_size)
21+
px = self.img.size[0] - font.getsize(tag_str)[0]
22+
draw_pen = ImageDraw.Draw(self.img)
23+
draw_pen.text((px, 0), tag_str, (255, 0, 0), font)
24+
self.img.save('face' + tag_str + '.jpg')
25+
return True
26+
27+
28+
solver = UnreadTagFace()
29+
solver.open('face.jpg')
30+
solver.draw(4)
31+
32+
33+
34+
35+
36+
37+
38+

Raynxxx/0000/face.jpg

15.3 KB
Loading

Raynxxx/0000/face4.jpg

15 KB
Loading

0 commit comments

Comments
 (0)