After loading an image file with PIL.Image, how can I determine whether the image file is a PNG/JPG/BMP/GIF? I understand very little about these file formats, can PIL get the format
metadata from the file header? Or does it need to 'analyze' the data within the file?
If PIL doesn't provide such an API, is there any python library that does?
Python Imaging Library is a free and open-source additional library for the Python programming language that adds support for opening, manipulating, and saving many different image file formats. It is available for Windows, Mac OS X and Linux. The latest version of PIL is 1.1.
Pillow supports reading JPEG Compressed or raw BLP1 images, and all types of BLP2 images.
Try:
img = Image.open(filename) print(img.format) # 'JPEG'
More info
https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.format
https://pillow.readthedocs.io/en/latest/handbook/image-file-formats.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With