Etienne Membrives
Etienne Membrives

Reputation: 879

Generate image for each font on a linux system using Python

I'm looking for a way to list all fonts installed on a linux/Debian system, and then generate images of some strings using these fonts. I'm looking for your advice as I kind of see how to do each part, but not to do both:

  1. To list all fonts on a UNIX system, xlsfonts can do the trick:

    import os
    list_of_fonts=os.popen("xslfonts").readlines()

  2. To render a string into an image using a font, I could use PIL (Python Imaging Library) and the ImageFont class.

However, ImagesFont.load expects a file name, whereas xlsfonts gives a kind of normalized font name, and the correspondence between the two doesn't seems obvious (I tried to search my system for files named as the output of xlsfonts, without results).

Does anyone has an idea on how I can do that? Thanks!

Upvotes: 5

Views: 1022

Answers (2)

user177800
user177800

Reputation:

you best bet is to do a find on all the fonts on the system, and then use ImagesFont.load() on the results of that list. I don't know where the fonts are on Debian, but they should be in a well known folder you can just do an os.walk and then feed the filenames in that way.

Upvotes: 1

mikerobi
mikerobi

Reputation: 20878

You can do this using pango, through the pygtk package. Pango can list fonts and render them.

Upvotes: 1

Related Questions