-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (37 loc) · 1.07 KB
/
main.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from PIL import Image, ImageDraw, ImageFont
font = ImageFont.truetype('MisekiBitmap.ttf', size=16)
image = Image.new('RGB', (320, 288), (219, 248, 199))
draw = ImageDraw.Draw(image)
draw.fontmode= "1"
keywords = []
text = '''
草々
kusa
https://kus.[AI]/so-so/
Version 0.2
'''
for i, line in enumerate(text.splitlines()):
current = 16
fill = (7, 24, 33)
is_keyword, keyword = False, ''
for ch in line:
if ch == '[':
fill = (48, 104, 80)
is_keyword = True
continue
elif ch == ']':
fill = (7, 24, 33)
is_keyword = False
keywords.append(keyword)
keyword = ''
continue
if is_keyword:
keyword += ch
text_width = draw.textlength(ch, font)
draw.text((current, 16 * i), ch, font=font, fill=fill)
# if i == 6:
# current += text_width - 1
# else:
current += text_width
image = image.resize((160, 144), resample=0)
image.save(f'so-so/assets/backgrounds/{"-".join(keywords)}-{len(text)}.png')