Articles // 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.

#!/usr/bin/python
#
# Get font family and style from .ttf files
# Paul Philippov, paul@ppds.ws, 2008-10-05
#

import sys
import os.path
from PIL import ImageFont

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

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

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

print f.font.family + " " + f.font.style

Comments // 2

Leave a comment

fok 10 months ago

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

Adr 9 months ago

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

Thanks

Cool site by the way

Tags

python, ttf, font, name

Technorati Delicious Flickr

Published on July 30, 2009

about 1 year ago

This article has 2 comments