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 imaage upon which this function is called or used.

Syntax: PIL.ImageOps.expand(image, border = 0, fill = 0)

image : The image to size and crop.
border : The border to be applied to the image in pixels.
fill: This defines the pixel fill value or color value to be applied. The default value is 0 which means the color is black.

Returns: An image with the required border.

Below is the implementation of ImageOps.expand()

Image used:





# Importing Image and ImageOps module from PIL package 
from PIL import Image, ImageOps 
# creating a image1 object 
im1 ="C:\Users\System-Pc\Desktop\a.jpg"
# applying expand method
# using border value = 20
# using fill = 50 which is brown type color
im2 = ImageOps.expand(im1, border = 20, fill = 50



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.