Python PIL | ImageFont.load_default()
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:
Last Updated :
02 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...