imghdr

imghdr — Determine the type of an image

Source code: Lib/imghdr.py

The imghdr module determines the type of image contained in a file or byte stream.

The imghdr module defines the following function:

imghdr.what(filename, h=None)

Tests the image data contained in the file named by filename, and returns a string describing the image type. If optional h is provided,