The Wayback Machine - https://web.archive.org/web/20241008061752/https://www.geeksforgeeks.org/python-pil-imagefont-load_default/
Open In App

Python PIL | ImageFont.load_default()

Last Updated : 02 Aug, 2019
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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)
  
# document 
dctx = ImageDraw.Draw(im)
dctx.text((0, 0), text, font = font)
del dctx
im = im.resize((im.width * 6, im.height * 8))
  
# img is saved as specified
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)
  
# document 
dctx = ImageDraw.Draw(im)
dctx.text((0, 0), text, font = font)
del dctx
im = im.resize((im.width * 6, im.height * 6))
  
# img is saved as specified
im.save("geeks2.png")


Output:



Previous Article
Next Article

Similar Reads

Python PIL | ImageFont.truetype()
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`pilfon
2 min read
Python PIL | GaussianBlur() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageFilter module contains definitions for a pre-defined set of filters, which can be used with the Image.filter() method. PIL.ImageFilter.GaussianBlur() method create Gaussian blur filter. Syntax: PIL.ImageFilter.GaussianBlur(radius=5) Par
1 min read
Python PIL | ImageDraw.Draw.pieslice()
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageDraw module provide simple 2D graphics for Image objects. You can use this module to create new images, annotate or retouch existing images, and to generate graphics on the fly for web use. ImageDraw.Draw.pieslice() Same as arc, but als
2 min read
Python PIL | Kernel() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageFilter module contains definitions for a pre-defined set of filters, which can be used with the Image.filter() method. PIL.ImageFilter.Kernel() Create a convolution kernel. The current version only supports 3x3 and 5x5 integer and float
2 min read
Python PIL | BoxBlur() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageFilter module contains definitions for a pre-defined set of filters, which can be used with the Image.filter() method.PIL.ImageFilter.BoxBlur() Blurs the image by setting each pixel to the average value of the pixels in a square box ext
2 min read
Python PIL | getbands() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.getbands() method returns a tuple containing the name of each band in the image.For example, getbands on an RGB image returns (“R”, “G”, “B”). Syntax: PIL.Image.getbands() Parameters: no arguments Returns: A tuple containing band names
1 min read
Python PIL | logical_and() and logical_or() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageChops module contains a number of arithmetical image operations, called channel operations (“chops”). These can be used for various purposes, including special effects, image compositions, algorithmic painting, and more. PIL.ImageChops.
1 min read
Python PIL | ImageChops.subtract() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageChops module contains a number of arithmetical image operations, called channel operations (“chops”). These can be used for various purposes, including special effects, image compositions, algorithmic painting, and more. PIL.ImageChops.
1 min read
Python PIL | UnsharpMask() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageFilter module contains definitions for a pre-defined set of filters, which can be used with the Image.filter() method.PIL.ImageFilter.UnsharpMask() method applies the Unsharp mask filter to the input image. Syntax: PIl.ImageFilter.Unsha
2 min read
Python PIL | ImageChops.subtract() and ImageChops.subtract_modulo() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. ImageChops.subtract() method - This method subtracts two images, dividing the result by scale and adding the offset. If omitted, scale defaults to 1.0, and offset to 0.0. Syntax: ImageChops.subtract(image1, image2, scale = 1.0, offset = 0) Param
2 min read
Python PIL | Image.crop() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.crop() method is used to crop a rectangular portion of any image. Syntax: PIL.Image.crop(box = None)Parameters: box - a 4-tuple defining the left, upper, right, and lower pixel coordinate.Return type: Image (Returns a rectangular regio
2 min read
Python PIL | ImageOps.expand() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. the ImageOps module contains a number of ‘ready-made’ image processing operations. This module is somewhat experimental, and most operators only work on L and RGB images.ImageOps.expand() adds a border to the image upon which this function is ca
1 min read
Adding Text on Image using Python - PIL
In Python to open an image, image editing, saving that image in different formats one additional library called Python Imaging Library (PIL). Using this PIL we can do so many operations on images like create a new Image, edit an existing image, rotate an image, etc. For adding text we have to follow the given approach. Approach Import moduleOpen ta
2 min read
Python PIL | ImageEnhance.Color() and ImageEnhance.Contrast() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageEnhance module contains a number of classes that can be used for image enhancement. ImageEnhance.Color() method - This class can be used to adjust the color balance of an image, in a manner similar to the controls on a color TV set. An
2 min read
Python PIL | ImageGrab.grabclipboard() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory. PIL.ImageGrab.grabclipboard() method takes a snapshot of the clipboard image, if any. Syntax: PIL.ImageGrab.grabclipboard() Parameters: n
1 min read
Python PIL | RankFilter() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageFilter module contains definitions for a pre-defined set of filters, which can be used with the Image.filter() method. PIL.ImageFilter.RankFilter() creates a rank filter. The rank filter sorts all pixels in a window of the given size, a
2 min read
Python PIL | ImageChops.screen() and ImageChops.offset() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. ImageChops.screen() method - This method is used to superimpose two inverted images on top of each other. Syntax: ImageChops.screen(image1, image2) Parameters: image1 first image image2 second image Return Value: An Image C/C++ Code # This will
2 min read
Python PIL | MedianFilter() and ModeFilter() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageFilter module contains definitions for a pre-defined set of filters, which can be used with the Image.filter() method. PIL.ImageFilter.MedianFilter() method creates a median filter. Picks the median pixel value in a window with the give
1 min read
Python PIL | Image.new() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.new() method creates a new image with the given mode and size. Size is given as a (width, height)-tuple, in pixels. The color is given as a single value for single-band images, and a tuple for multi-band images (with one value for each
2 min read
Python PIL | paste() and rotate() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.Image.paste() method is used to paste an image on another image. This is where the new() method comes in handy. Syntax: PIL.Image.Image.paste(image_1, image_2, box=None, mask=None) OR image_object.paste(image_2, box=None, mask=None)Par
2 min read
Python PIL | ImageChops.darker() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. ImageChops.darker() method is used to compare two images pixel by pixel, and returns a new image containing the darker values. Syntax: ImageChops.darker(image1, image2) Parameters: image1: It is the image object or image path of first image. ima
1 min read
Python PIL | Image.split() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. Image.split() method is used to split the image into individual bands. This method returns a tuple of individual image bands from an image. Splitting an “RGB” image creates three new images each containing a copy of one of the original bands (re
1 min read
Python PIL | Image filter with ImageFilter module
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageFilter module contains definitions for a pre-defined set of filters, which can be used with the Image.filter() method. Image used: Filters - The current version of the library provides the set of predefined image enhancement filters: 1.
2 min read
Python PIL | ImageChops.add() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageChops module contains a number of arithmetical image operations, called channel operations (“chops”). These can be used for various purposes, including special effects, image compositions, algorithmic painting, and more. PIL.ImageChops.
2 min read
Python PIL | copy() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.copy() method copies the image to another image object, this method is useful when we need to copy the image but also retain the original. Syntax:Image.copy() Parameters: no arguments Returns:An image object # Importing Image module fr
1 min read
Python PIL | composite() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.composite() method creates composite image by blending images using a transparency mask. Here, mask is another image which remains transparent when composite together. Syntax: PIL.Image.composite(image1, image2, mask) Parameters: image
2 min read
Python PIL | ImageChops.multiply() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageChops module contains a number of arithmetical image operations, called channel operations (“chops”). These can be used for various purposes, including special effects, image compositions, algorithmic painting, and more. PIL.ImageChops.
1 min read
Python PIL | ImageChops.lighter() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageChops module contains a number of arithmetical image operations, called channel operations (“chops”). These can be used for various purposes, including special effects, image compositions, algorithmic painting, and more. PIL.ImageChops.
1 min read
Python PIL | blend() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.blend() method creates a new image by interpolating between two input images, using a constant alpha. Syntax: PIL.Image.blend(image1, image2, alpha). Parameter: image1: first image image2: second image, must have the same mode and size
2 min read
Python PIL | MinFilter() and MaxFilter() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageFilter module contains definitions for a pre-defined set of filters, which can be used with the Image.filter() method. PIL.ImageFilter.MinFilter() method creates a min filter. Picks the lowest pixel value in a window with the given size
1 min read
Article Tags :
Practice Tags :