0

I'm trying Pygments to convert some code into a highlighted image. Here's the Python script:

from pygments.lexers import PhpLexer
from pygments.formatters import ImageFormatter
from pygments.filters import CodeTagFilter
from pygments import highlight
code = open("myPhpCode.php").read()
formatter = ImageFormatter()
with open("myPhpCodeAsAnImage.png", "w+") as f:
    f.write(highlight(code, PhpLexer(), formatter))

I've tried Python2 and Python3, on MacOs, I have also tried to set ImageFormatter's option "font_name="pathToFont" with the full path of a font I know exists, and I always get the following error :

pygments.formatters.img.FontNotFound: No usable fonts named: "Menlo"

Is there something I'm missing?

Lucien S.
  • 5,123
  • 10
  • 52
  • 88

1 Answers1

0

I was having the same error, check paths mention in here.

Verify that you have the Menlo font. At this moment pygments are only loading .ttf files and ignoring .ttc.

In my case, Menlo font extension was .ttc instead of .ttf I just renamed that file and all works.