Create an image for each font on a Linux system using Python

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

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

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

  • To display a string in an image using a font, I could use PIL (Python Image Library) and the ImageFont class.

However, ImagesFont.load expects a file name, while xlsfonts gives a kind of normalized font name, and the correspondence between them does not seem obvious (I tried to search my system for files named as xlsfonts output with no results).

Does anyone have an idea how I can do this? Thanks!

+4
source share
2 answers

You can do this using pango through the pygtk package. Pango can display fonts and display them.

+1
source

it is best to make find on all fonts in the system, and then use ImagesFont.load() based on the results of this list. I don’t know where the fonts are on Debian, but they should be in a well-known folder that you can just make os.walk and then feed the file names this way.

+1
source

Source: https://habr.com/ru/post/1303054/


All Articles