Change the ratio between width and height of an image using Python - Pillow Last Updated : 23 Dec, 2020 Comments Improve Suggest changes Like Article Like Report Python Imaging Library (expansion of PIL) is the de facto image processing package for the Python language. It incorporates lightweight image processing tools that aid in editing, creating, and saving images. This module is not preloaded with Python. So to install it execute the following command in the command-line: pip install pillowTo change the ratio of height and width we will add or subtract any random value from them. Functions UsedImage.open(fp, mode=’r’) method: This method is used to open the image.Image.resize(size, resample=0) method: This method is used to resize the image. Interpolation happens during the resize process, due to which the quality of image changes whether it is being upscaled (resized to a higher dimension than original) or downscaled (resized to a lower Image then original).Approach:We will first take an image.Then we will find its height and width.Then we will add and subtract any random number from them to change the ratio.Then we will save the image.Example: Image Used: Python3 # Python program to change the ratio of height and # width of an image from PIL import Image # Taking image as input img = Image.open('logo.png') # Getting height and width of the image height = img.size[0] width = img.size[1] # Printing ratio before conversion print('Ratio before conversion:', width/height) # Changing the height and width of the image width = width + 25 height = height - 25 # Resizing the image img = img.resize((width ,height), Image.ANTIALIAS) # Printing the ratio after conversion print('Ratio after conversion:', width/height) # Saving the resized image img.save('Resized Image.png') Output: Ratio before conversion: 1.0 Ratio after conversion: 1.25Output Image: Comment More infoAdvertise with us Next Article Change the ratio between width and height of an image using Python - Pillow A aditya_taparia Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2020 Python-pil Practice Tags : python Similar Reads How to find width and height of an image using Python? Finding the width and height of an image in Python means reading the image and determining its dimensions in pixels. For example an image might have a height of 135 pixels and a width of 600 pixels. Letâs explore some common methods to find an imageâs width and height.1. Using OpenCV (cv2)OpenCV is 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 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 Getting width and height of an image in Pygame Prerequisites: Pygame To use graphics in python programs we use a module called Pygame. Pygame provides high functionality for developing games and graphics in Python. Nowadays Pygame are very much popular to build simple 2D games. In order to run a program written in Python using Pygame module, a s 3 min read How to merge images with same size using the Python 3 module pillow? In this article, the task is to merge image with size using the module pillow in python 3. Python 3 module pillow : This is the update of Python Imaging Library. It is a free and open-source additional library for the Python programming language that adds support for opening, manipulating, and savi 2 min read Like