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 14 years ago)

Article tags: font, python, script

Comments (4)

fok to TrueType font name extractor

Very useful! Thanks!
I made a bash script using this as basis to organize my fonts.

about 14 years ago

Adr to TrueType font name extractor

Please mr. fok
Could you post your bash script somewhere on the web please?


Cool site by the way

about 14 years ago

JCP to TrueType font name extractor

Tested with 2600 ttf files and worked like a charm! Thumbs up! Thank you for sharing your code!!!

over 9 years ago

karim reefat to TrueType font name extractor

Thanks you very much for sharing the code, i use it to get the names of the my windows fonts and it work great.

over 8 years ago