Skip to content

Commit 0ac82c9

Browse files
committed
add p012
1 parent 00e1556 commit 0ac82c9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

prjs/012-draw-text-on-img/app.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from PIL import Image, ImageFont, ImageDraw
2+
3+
data = [
4+
{
5+
'id': '3c1d4d3c-c3b4-4b81-804a-0f82b6f35e29',
6+
'name': '坂田银八',
7+
},
8+
{
9+
'id': 'b46c36c6-9d84-49a6-a706-a8e216431184',
10+
'name': '志村新八',
11+
}
12+
]
13+
14+
15+
def main(bg_img_file_name, configs):
16+
for user in configs:
17+
draw_text_on_image(bg_img_file_name, user)
18+
19+
20+
def draw_text_on_image(bg_img_file_name, user):
21+
im = Image.open(bg_img_file_name)
22+
draw = ImageDraw.Draw(im)
23+
font = ImageFont.truetype("SourceHanSansCN-Regular.otf", 33)
24+
draw.text((190, 560), f"{user['name']}同学:", font=font, fill="#000")
25+
im.save(f"out/{user['id']}.png")
26+
27+
28+
def _create_bg_image():
29+
im = Image.new("RGB", (750, 1132), "#FFF")
30+
im.save('bg.png')
31+
32+
33+
if __name__ == '__main__':
34+
main(
35+
bg_img_file_name='bg.png',
36+
configs=data,
37+
)
38+

prjs/012-draw-text-on-img/bg.png

4.92 KB
Loading

0 commit comments

Comments
 (0)