Get Image Height with Pillow
Pillow - Get Image Height
To get the height of an image in pixels with Pillow in Python, you can use PIL.Image.height attribute.
The attribute returns the height of this image in pixels.
In this tutorial, you will learn how to get the height of a given image with Pillow library, by writing some example programs.
Examples
1. Get height of given image in pixels
In the following program, we open an image using Image.open(), and then get the height of this image using height attribute of Image class object.
The input image we have taken has dimensions of 640x427
, of which 640
is the width and 427
is the height. Therefore, when we get the height of the image, the height attribute must return 427
.
Python Program
from PIL import Image
# Open an image
img = Image.open("test_image_house.jpg")
# Get image height
height = img.height
print(height)
Output
427
Summary
In this Python Pillow Tutorial, we described how to get the height of an image in pixels using PIL.Image.height attribute, with the help of examples.