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 M 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 Like