13

I want to generate a .PNG image for every glyph in a .TTF font file. How do I do that?

2
  • 1
    You mean other than typing one letter in Photoshop, save, next letter, save...?
    – Tetsujin
    Jul 10, 2018 at 7:22
  • 1
    In FontForge you can export one glyph as image. But if you want automation then it's more complicated
    – Mikhail V
    Jul 13, 2018 at 15:11

5 Answers 5

9

You can use Python with FontForge, it has a Python 2.7 interpreter.

On Windows: after installing FontForge, locate the "bin" in installation path and add it to the Windows system path, in my case it is:

c:\Program Files (x86)\FontForgeBuilds\bin\

This dir contains ffpython.exe so after adding it to PATH you can directly run a .py script in console.

> ffpython myscript.py

To export all glyphs you can use this simple script:

import fontforge
F = fontforge.open("perpetua.ttf")
for name in F:
    filename = name + ".png"
    # print name
    F[name].export(filename)
    # F[name].export(filename, 600)     # set height to 600 pixels

documentation:
http://fontforge.github.io/python.html#Glyph
http://fontforge.github.io/python.html#Font

2
  • Any ideas in order to select export coulour ?
    – snowflake
    Sep 2, 2021 at 9:20
  • In the example, to get a height of 600 pixels, I have to use 599
    – kongo09
    Jan 17, 2022 at 19:21
4

fontforge has switched to a python scripting language. Create a file exportGlyphs.py:

import os
from fontforge import *

font = open(os.sys.argv[1])
for glyph in font:
    if font[glyph].isWorthOutputting():
        font[glyph].export(font[glyph].glyphname + ".png")

Then run fontforge as:

fontforge -script exportGlyphs.py YOURFONT.ttf

Bingo. A whole bunch of .png files for each glyph.

2

This may be an old question, but I found the following batch file works with ImageMagick 7:

@ECHO OFF
set f=wingding.TTF
set ps=400
set bg=white
set ext=png
set s=600x600
set alpha=A B C D E F G H I J K L M N O P Q R S T U V W Z Y Z
set num=0 1 2 3 4 5 6 7 8 9
For %%X in (%alpha% %num%) do (
convert -font %f% -pointsize %ps% -size %s% -background %bg% label:%%X 
%%X.%ext%)
pause
exit

NOTE: This conversion only works with a limited selection of font characters. It works well for all capital letters. Just install ImageMagick and make sure it is in your environment path. Include "legacy" commands in your installation.

1

Output svg and png, the file name contains Unicode Decimal Code.

export-ttf.py

# cmd.exe
# "C:\Program Files (x86)\FontForgeBuilds\bin\ffpython.exe" export-ttf.py
# API: https://fontforge.org/docs/scripting/python/fontforge.html
# Download: https://fontforge.org/en-US/
import fontforge
font = fontforge.open("font.ttf")
for name in font:
    glyph = font[name]
    fullnamesvg = name + " , " + str(glyph.unicode) + " , " + str(glyph.altuni) + ".svg"
    fullnamepng = name + " , " + str(glyph.unicode) + " , " + str(glyph.altuni) + ".png"
    glyph.export(fullnamesvg)
    glyph.export(fullnamepng, 1024)
0

This online app does just that very easily and visual - although is not open source :( it could help to quickly generate transparent glyphs pngs from given ttf to quickly test. and a manifest of all the glyphs dimensions and features: http://kvazars.com/littera/

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.