Only supported for TrueType fonts
时间: 2023-11-05 19:23:15 浏览: 38
This error message usually occurs in the PIL library's ImageDraw module when attempting to use a font format that is not supported. The error message suggests that only TrueType fonts are supported.
To fix this error, you can try using a TrueType font instead of the font format you are currently using. You can specify a TrueType font in PIL using the `ImageFont.truetype()` method. Here is an example:
```python
from PIL import Image, ImageDraw, ImageFont
# Specify TrueType font
font = ImageFont.truetype('arial.ttf', size=20)
# Draw text on image
image = Image.new('RGB', (100, 100), color='white')
draw = ImageDraw.Draw(image)
draw.text((10, 10), 'Hello, World!', fill='black', font=font)
image.show()
```
In this example, we specify a TrueType font by calling `ImageFont.truetype()` and passing in the font file path and font size. You can replace `'arial.ttf'` with the path to the TrueType font file you want to use.