发布于 2015-09-11 16:16:18 | 569 次阅读 | 评论: 0 | 来源: 网络整理
The ImageFont module defines a class with the same name. Instances of this class store bitmap fonts, and are used with the PIL.ImageDraw.Draw.text() method.
PIL uses its own font file format to store bitmap fonts. You can use the :command`pilfont` utility to convert BDF and PCF font descriptors (X window font formats) to this format.
Starting with version 1.1.4, PIL can be configured to support TrueType and OpenType fonts (as well as other font formats supported by the FreeType library). For earlier versions, TrueType support is only available as part of the imToolkit package
from PIL import ImageFont, ImageDraw
draw = ImageDraw.Draw(image)
# use a bitmap font
font = ImageFont.load("arial.pil")
draw.text((10, 10), "hello", font=font)
# use a truetype font
font = ImageFont.truetype("arial.ttf", 15)
draw.text((10, 25), "world", font=font)
Load a font file. This function loads a font object from the given bitmap font file, and returns the corresponding font object.
参数: | filename – Name of font file. |
---|---|
返回: | A font object. |
引发 IOError: | If the file could not be read. |
Load font file. Same as load(), but searches for a bitmap font along the Python path.
参数: | filename – Name of font file. |
---|---|
返回: | A font object. |
引发 IOError: | If the file could not be read. |
Load a TrueType or OpenType font file, and create a font object. This function loads a font object from the given file, and creates a font object for a font of the given size.
This function requires the _imagingft service.
参数: |
|
---|---|
返回: | A font object. |
引发 IOError: | If the file could not be read. |
返回: | (width, height) |
---|
Create a bitmap for the text.
If the font uses antialiasing, the bitmap should have mode “L” and use a maximum value of 255. Otherwise, it should have mode “1”.
参数: |
|
---|---|
返回: | An internal PIL storage memory instance as defined by the PIL.Image.core interface module. |