Get Image Width with Pillow in Python

Pillow – Get Image Width

To get the width of an image in pixels with Pillow in Python, you can use PIL.Image.width attribute.

The attribute returns the width of this image in pixels.

In this tutorial, you will learn how to get the width of a given image with Pillow library, by writing some example programs.


1. Get width of given image in pixels

In the following program, we open an image using, and then get the width of this image using width 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 width of the image, the width attribute must return 640.

Pillow - Get Image Width - Input image

Python Program

from PIL import Image

# Open an image
img ="test_image_house.jpg")

# Get image width
width = img.width




In this Python Pillow Tutorial, we described how to get the width of an image in pixels using PIL.Image.width attribute, with the help of examples.

Related Tutorials

Code copied to clipboard successfully 👍