I have a custom TrueType font (TTF) that consists of a bunch of icons, which I'd like to render as individual bitmaps (GIF, PNG, whatever) for use on the Web. You'd think this is a simple task, but apparently not? There is a huge slew of TTF-related software here:
http://cg.scs.carleton.ca/~luc/ttsoftware.html
But it's all varying levels of "not quite what I want", broken links and/or hard to impossible to compile on a modern Ubuntu box -- eg. dumpglyphs (C++) and ttfgif (C) both fail to compile due to obscure missing dependencies. Any ideas?
Try PIL's ImageDraw and ImageFont module
Code would be something like this
Use some imaging software like the Gimp to display all the characters you're interested in, then save each one to a file. Not fast or efficient, but you know what you'll be getting.
Here's a working implementation of S.Mark's answer that dumps out chars 'a' to 'z' in black into correctly-sized PNGs:
A more concise, and more reliable version of the other answers (which cut off parts of some glyphs for me):
I’d be interested to know whether there’s a better way to construct a PIL Image from the ImagingCore object that
font.getmask()
returns.