aggdraw cannot load font (no text renderer)

2019-07-28 01:02发布

问题:

I've installed aggdraw on OS X 10.8 using Apple's stock Python (2.7.2) using these instructions. Before doing so, I used homebrew to install freetype, and I modified aggdraw's setup.py to point to my freetype installation (FREETYPE_ROOT = "/usr/local/Cellar/freetype/2.4.10/" on line 32).

Despite all of this, when I try to load a font, I get:

$ python test.py 
Traceback (most recent call last):
  File "test.py", line 9, in <module>
      font = Font('black', '/Library/Fonts/Georgia.ttf')
IOError: cannot load font (no text renderer)

test.py looks like this:

from PIL import Image
from aggdraw import Draw, Brush, Pen, Font

size = 500, 500
img = Image.new("RGBA", size)
draw = Draw(img)
draw.rectangle((0, 0) + size, Brush((255, 255, 255), opacity=255))
draw.setantialias(True)
font = Font('black', '/Library/Fonts/Georgia.ttf')
draw.text((100, 100), "hello, world", font)
draw.flush()
img.save("test.png")

What do I need to do in order to load and use fonts in aggdraw?

回答1:

The problem was with my FREETYPE_ROOT. Line 32 of aggdraw's setup.py should be as follows: FREETYPE_ROOT = "/usr/local"

After changing that line, rebuilding and reinstalling, the test.py script above works fine.

I've updated my install script to apply that patch.