views:

123

answers:

2

Hello,

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!

A: 

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

mikerobi
Pango seems to do the job, thanks!
Etienne Membrives
A: 

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.

fuzzy lollipop
There is the `/usr/share/fonts` path on Debian. But, as I said, it is not obvious that everything is there and in a directly usable form. As an example, `xlsfonts` and several graphical programs return that I have a font named "nimbus roman", but the only file called "Nimbus" is in my home folder and not in that system directory (and not in a ~/.fonts/ folder either, just a regular one). Thus, searching this way is I think not really reliable.
Etienne Membrives
the file name of the fonts will not necessarily match what xlsfonts shows, also one font file can contain many fonts in some cases.
fuzzy lollipop