6

I'm trying to find out what fonts are available to be used in PIL with the font = ImageFont.load() and/or ImageFont.truetype() function. I want to create a list from which I can sample a random font to be used. I haven't found anything in the documentation so far, unfortunately.

Linda
  • 1,003
  • 1
  • 11
  • 25
  • 1
    You can use any font file you have on your computer and can load millions more from anywhere on the Internet https://stackoverflow.com/a/64716673/2836621 so there's no real answer to this. – Mark Setchell Dec 04 '20 at 14:00

1 Answers1

9

I have so far not found a solution with PIL but matplotlib has a function to get all the available fonts from the system:

system_fonts = matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')

The font can then be loaded using fnt = ImageFont.truetype(font, 60)

Linda
  • 1,003
  • 1
  • 11
  • 25
  • This didn't work for me, but `from matplotlib import font_manager font_manager.get_font_names()` did, perhaps an update to 3.6.0 – Luce Aug 10 '23 at 10:01