Skip to content

Instantly share code, notes, and snippets.

@magikmw
Created January 10, 2012 15:34
Show Gist options
  • Save magikmw/1589637 to your computer and use it in GitHub Desktop.
Save magikmw/1589637 to your computer and use it in GitHub Desktop.
ttf to png
#!/usr/bin/python
#USAGE:
#python TCODfont.py /path/to/font/font.ttf 12
import Image, ImageFont, ImageDraw, sys
fontpath = sys.argv[1]
fontpoint = int(sys.argv[2])
image = Image.new('RGB', [fontpoint*16, fontpoint*16])
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(fontpath, fontpoint)
i = 0
for row in range(0, 16):
for col in range(0, 16):
xpos = fontpoint*col+1
ypos = fontpoint*row
draw.text((xpos, ypos), chr(i), font=font)
i += 1
image.save('tcod.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment