Skip to content

Instantly share code, notes, and snippets.

@trashbyte
Last active December 20, 2020 22:04
Show Gist options
  • Save trashbyte/27a45ad1daf6efb20ef3cd80382ba920 to your computer and use it in GitHub Desktop.
Save trashbyte/27a45ad1daf6efb20ef3cd80382ba920 to your computer and use it in GitHub Desktop.
Mass importing pixel font glyphs into FontForge

First, you'll need separate images for each glyph, with transparent backgrounds. Each file should have a name matching its character, e.g. a.png. Depending on the format your font is in, this could be pretty tedious. Don't worry, this is the worst part.

Once you have your font images, you'll run pixel2svg on them. You could run it on every image in a directory with something like this:

for f in imgfolder/*.png; do python pixel2svg.py $f; done

Then you should have an svg for each glyph. Open FontForge and create a new font. Choose File > Execute Script and paste in the following:

import fontforge
svg_path = "/path/to/svgs/"
font = fontforge.font()
for c in ['a','b','c']:
char = font.createMappedChar(c)
char.importOutlines(svg_path+c+'.svg')

Make sure python is selected as the script type, not FontForge's own scripting language. Obviously, you'll need to change svg_path to the place where your svg files are, and add all of the glyphs you want to import to the list in the for loop. Uppercase and lowercase letters could be a problem on Windows, since filenames are case-insensitive. You'd have to modify the script accordingly.

Once you run the script, you should have a FontForge project open with all your glyphs imported. Don't forget to save it!

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