Skip to content

Commit 8627bf1

Browse files
committed
solve ex0000
1 parent a32d9f7 commit 8627bf1

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎GitRangerLiu/0000/cat.jpg‎

9.59 KB
Loading

‎GitRangerLiu/0000/cat2.jpg‎

11.8 KB
Loading

‎GitRangerLiu/0000/img_addnum.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from PIL import Image, ImageDraw, ImageFont
2+
3+
4+
def img_addnum(img_name, num):
5+
im = Image.open(img_name)
6+
draw = ImageDraw.Draw(im)
7+
8+
#width and height
9+
w = im.width;
10+
h = im.height;
11+
print h, w
12+
13+
#load font
14+
#fnt = ImageFont.load_default()
15+
fnt = ImageFont.truetype('arial.ttf', int(h * 0.15))
16+
17+
18+
draw.text((w * 0.9 , h * 0.05), num, font=fnt, fill=(255, 0, 0, 128))
19+
im.save(img_name.split('.')[0] + '2.jpg')
20+
21+
if __name__ == '__main__':
22+
img_addnum('cat.jpg', '3')
23+
24+

0 commit comments

Comments
 (0)