Add padding to the image with Python - Pillow Last Updated : 16 Mar, 2021 Comments Improve Suggest changes Like Article Like Report 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 pillowApproachImport moduleOpen imageSet values for paddingSet different dimensions for imagePass the padding values to the imageSave new image Input Image: Program : Python3 from PIL import Image image = Image.open("input.jpg") right = 100 left = 100 top = 100 bottom = 100 width, height = image.size new_width = width + right + left new_height = height + top + bottom result = Image.new(image.mode, (new_width, new_height), (0, 0, 255)) result.paste(image, (left, top)) result.save('output.jpg') Output: 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 More infoAdvertise with us Next Article Add padding to the image with Python - Pillow mohanapranes Follow Improve Article Tags : Python Python-pil Practice Tags : python Similar Reads Python | Working with the Image Data Type in pillow In this article, we will look into some attributes of an Image object that will give information about the image and the file it was loaded from. For this, we will need to import image module from pillow. Image we will be working on : size() method - It helps to get the dimensions of an image. IMG = 2 min read How to add text on an image using pillow in Python ? Prerequisites: PIL In this article we'll see how we can add text on an image using the pillow library in Python. Python Imaging Library (PIL) is the de facto image processing package for Python language. It incorporates lightweight image processing tools that aids in editing, creating and saving ima 2 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 2 min read Create and save animated GIF with Python - Pillow Prerequisites: pillow In this article, we are going to use a pillow library to create and save gifs. GIFs: The Graphics Interchange Format(gif) is a bitmap image format that was developed by a team at the online services provider CompuServe led by American computer scientist Steve Wilhite on 15 June 3 min read Change image resolution using Pillow in Python Prerequisites: Python pillow PIL is the Python Imaging Library which provides the python interpreter with an in-depth file format support, an efficient internal representation, and fairly powerful image processing capabilities. Changing the resolution of an image simply means reducing or increasing 2 min read Create transparent png image with Python - Pillow To create a transparent png using Python3, the Pillow library is used. The Pillow library comes with python itself. If python is unable to find Pillow library then open the command prompt and run this command:- pip install Pillow Note: If you got any problem installing Pillow using pip, then install 3 min read Python Pillow - Working with Images In this article, we will see how to work with images using Pillow in Python. We will discuss basic operations like creating, saving, rotating images. So let's get started discussing in detail but first, let's see how to install pillow. Installation To install this package type the below command in t 4 min read Expanding the Canvas Without Resizing in Python Pillow The Python Imaging Library (PIL) is a powerful tool for image processing in Python, offering a wide range of functionalities from basic image manipulations to complex operations. One of the useful features of PIL is the ability to expand the canvas of an image without resizing the original content. 4 min read Convert PNG to ICO with Pillow in Python In this article, we will convert PNG to ICO using pillow in Python. Convert PNG to ICO with Pillow in Python Before moving further first let us understand what is PNG and ICO. The PNG stands for Portable Network Graphic. It is often used to store web graphics. The png image can be used with transpar 2 min read How to Concatenate image using Pillow in Python ? Prerequisites: Python Pillow Concatenate image means joining of two images. We can merge any image whether it has different pixels, different image formats namely, 'jpeg', 'png', 'gif', 'tiff', etc. In python, we can join two images using the Python image library also known as the pillow library. In 3 min read Like