VOOZH about

URL: https://www.geeksforgeeks.org/python/add-padding-to-the-image-with-python-pillow/

⇱ Add padding to the image with Python - Pillow - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Add padding to the image with Python - Pillow

Last Updated : 23 Jul, 2025

Prerequisites: Pillow(python library)

Padding is the space between the contents, the container, and the border. An image can be considered content to some container and extra padding can be added to it. This article depicts how this can be done.  Padding can be added by straightaway supplying the values for the side to be padded. These values can then be passed to the function to create a new image.

Installation

This module is not preloaded with Python. So to install it execute the following command in the command-line:

pip install pillow

Approach

  • Import module
  • Open image
  • Set values for padding
  • Set different dimensions for image
  • Pass the padding values to the image
  • Save new image

Input Image:

👁 Image

Program :

Output:

👁 Image

The output generated is just the input image with a padding added to it. Here it appears as a border, since the values given for each side were equal. For different values non-uniform padding can be observed.

Comment
Article Tags:
Article Tags: