Skip to content

Commit ee6a630

Browse files
committed
练习题0000
1 parent ef9e731 commit ee6a630

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed
21 KB
Binary file not shown.

patchlion/0000/DrawHeadImage.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
__author__ = 'PatchLion'
3+
4+
from PIL import Image, ImageDraw,ImageFont
5+
6+
def drawNumberOnIcon(imgpath, number):
7+
img = Image.open(imgpath)
8+
if (None == img):
9+
print('打开图片失败')
10+
return
11+
12+
img = img.resize((160, 160))
13+
14+
print(imgpath, "->", img.format, img.size, img.mode)
15+
draw = ImageDraw.Draw(img)
16+
img_size = img.size
17+
18+
font = ImageFont.truetype("Blackout-Midnight.ttf", size=int(img_size[1]/4))
19+
text_size = font.getsize(str(number))
20+
21+
draw.text((img_size[0]-text_size[0], 0), str(number), font=font, fill=(255, 0, 0))
22+
23+
img.save('icon_withnumber.bmp')
24+
25+
print('生成图片成功')
26+
27+
28+
drawNumberOnIcon("icon.bmp", 21)

patchlion/0000/icon.bmp

5.27 MB
Binary file not shown.

patchlion/0000/icon_withnumber.bmp

75.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)