forked from iswbm/love-with-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_love_in_picture.py
More file actions
25 lines (18 loc) · 816 Bytes
/
Copy pathall_love_in_picture.py
File metadata and controls
25 lines (18 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from PIL import Image, ImageDraw, ImageFont
font_size, text = 7, "我喜欢你!"
input_img_path = "/Users/MING/Github/love-with-python/girl.jpeg"
output_img_path = "/Users/MING/Github/love-with-python/girl.png"
img_raw = Image.open(input_img_path)
img_array = img_raw.load()
img_new = Image.new("RGB", img_raw.size, (0, 0, 0))
draw = ImageDraw.Draw(img_new)
font = ImageFont.truetype('/System/Library/Fonts/PingFang.ttc', font_size)
def character_generator(text):
while True:
for i in range(len(text)):
yield text[i]
ch_gen = character_generator(text)
for y in range(0, img_raw.size[1], font_size):
for x in range(0, img_raw.size[0], font_size):
draw.text((x, y), next(ch_gen), font=font, fill=img_array[x, y], direction=None)
img_new.convert('RGB').save(output_img_path)