Python PIL | ImageFont.load_default()
Last Updated :
02 Aug, 2019
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities.
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
ImageFont.load_default() Load a âeat healthy live healthyâ default font.
Syntax: ImageFont.load_default()
Parameters:
text -write text to load.
Returns: A font object.
from PIL import Image, ImageFont, ImageDraw
text = "eat healthy live healthy"
font = ImageFont.load_default()
im = Image.new("L", font.getsize(text), 255)
dctx = ImageDraw.Draw(im)
dctx.text((0, 0), text, font = font)
del dctx
im = im.resize((im.width * 6, im.height * 8))
im.save("geeks3.png")
|
Output:

Another Example:Here changing the text, Load a âbetter than nothingâ default font.
from PIL import Image, ImageFont, ImageDraw
text = "better than nothing"
font = ImageFont.load_default()
im = Image.new("L", font.getsize(text), 255)
dctx = ImageDraw.Draw(im)
dctx.text((0, 0), text, font = font)
del dctx
im = im.resize((im.width * 6, im.height * 6))
im.save("geeks2.png")
|
Output:
