Paul Philippov

home is where ~/ is

TrueType font name extractor

Found in archives. This short script can extract family name and style out of a True Type Font file. Useful for building a catalog of fonts and such.

# Get font family and style from .ttf files
# Paul Philippov,, 2008-10-05

import sys
import os.path
from PIL import ImageFont

if len(sys.argv) <= 1:
  print "Usage: %s <fontname>" % sys.argv[0]

filename = sys.argv[1]
if not os.path.exists(filename) or not os.path.isfile(filename):
  print "Error: %s is not a file" % filename

  f = ImageFont.truetype(filename, 1)
  print "Error: %s is not a Truetype font" % filename

print + " " +

Published on July 30, 2009 (over 7 years ago)

Article tags: font, python, script