Get Image Format with Pillow
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.
Examples
1. Get format of given image
In the following program, we open an image using Image.open(), 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 = Image.open("test_image_house.jpg")
# Get image format
format = img.format
print(format)
Output
JPEG
Summary
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.