-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_images.py
36 lines (24 loc) · 903 Bytes
/
generate_images.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
import os
import emoji
from PIL import Image, ImageFont
from pilmoji import Pilmoji
import subprocess
# Get a list containing all the available emojis
emojis = list(emoji.EMOJI_DATA.keys())
print(len(emojis))
for size in [16, 32, 64, 128, 256]:
directory = f"./png/{size}x{size}"
os.makedirs(directory, exist_ok=True)
for e in emojis:
try:
filename = f"{directory}/{e}.png"
if os.path.exists(filename):
continue
with Image.new('RGBA', (size, size), (0, 0, 0, 0)) as image:
font = ImageFont.truetype('Arial.ttf', size)
with Pilmoji(image) as pilmoji:
pilmoji.text((0, 0), e, (0, 0, 0), font)
# Save the image as a PNG file
image.save(filename)
except Exception as ex:
print("Couldn't process emoji: ", e, ex)