Get Image Format with Pillow in Python

Pillow – Get Image Format

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

The attribute returns the file format of the source file.

Note: If the image is created by the library itself (via a factory function, or by running a method on an existing image), this format attribute is set to None.


1. Get format of given image

In the following program, we open an image using, and then get the format of the image using format attribute of Image class object.

Python Program

from PIL import Image

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

# Get image format
format = img.format




In this Python Pillow Tutorial, we learned how to get the format of an image using PIL.Image.format attribute, with the help of examples.

Related Tutorials

Code copied to clipboard successfully 👍