Skip to content

Instantly share code, notes, and snippets.

@slntopp
Last active February 19, 2024 15:47
Show Gist options
  • Save slntopp/e26ffc2beaac641a49b710bc5243098d to your computer and use it in GitHub Desktop.
Save slntopp/e26ffc2beaac641a49b710bc5243098d to your computer and use it in GitHub Desktop.
Convert ttf pack into (png) images, quick
from PIL import Image, ImageFont, ImageDraw
characters = "abcdefghijklmnopqrstuvwxyz0123456789"
capitalized_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
special_characters = ".:(*!?{}})#$%*&-+@"
special_characters_names = {
".": "period",
":": "colon",
"(": "left_parenthesis",
"*": "asterisk",
"!": "exclamation",
"?": "question",
"{": "left_brace",
"}": "right_brace",
")": "right_parenthesis",
"#": "hash",
"$": "dollar",
"%": "percent",
"*": "asterisk",
"&": "ampersand",
"-": "minus",
"+": "plus",
"@": "at"
}
font = ImageFont.truetype("Exo/static/Exo-Bold.ttf", 128)
def make_char(char, name = None):
image = Image.new("RGBA", (100, 100), (255, 255, 255, 0))
draw = ImageDraw.Draw(image)
draw.text((50, 100), char, (0, 0, 0, 255), font=font, anchor="mb")
if not name:
name = char
image.save("./Exo/%s.png" % name, "PNG")
for char in characters:
make_char(char)
for char in capitalized_characters:
make_char(char, "capital_%s" % char)
for char in special_characters:
make_char(char, special_characters_names[char])
image = Image.new("RGBA", (100, 100), (255, 255, 255, 0))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("Exo/static/Exo-Bold.ttf", 64)
draw.text((50, 100), "Exo", (0, 0, 0, 255), font=font, anchor="mb")
image.save("Exo/Exo.png", "PNG")
@slntopp
Copy link
Author

slntopp commented Feb 19, 2024

For example, i needed it to create Emoji pack for Telegram, worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment