Skip to content

Instantly share code, notes, and snippets.

@asketchyfish
Created July 17, 2015 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asketchyfish/2f3e45cd1b80829dc272 to your computer and use it in GitHub Desktop.
Save asketchyfish/2f3e45cd1b80829dc272 to your computer and use it in GitHub Desktop.
Make TTF font into images
#!/usr/bin/env python
import Image, ImageFont, ImageDraw
# use a truetype font
font = ImageFont.truetype("font.ttf", 200)
im = Image.new("RGBA", (300, 300))
draw = ImageDraw.Draw(im)
W, H = (300,300)
i = 1
for code in range(ord(u'\uf000'), ord(u'\uf100')):
w, h = draw.textsize(unichr(code), font=font)
im = Image.new("RGBA", (W, H))
draw = ImageDraw.Draw(im)
draw.text(((W-w)/2,0), unichr(code), font=font, fill="#000000")
im.save("images/" + unichr(code).encode("unicode_escape") + ".png")
i = i + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment