When you know you are working with image files, it's frequently necessary to verify their type to ensure they are in a format your software is able to handle.
One possible use case is to ensure they are images in a format that a browser might be able to show back when they are uploaded to a website.
The type of a multimedia file can usually be detected by inspecting the file header, the initial part of a file that stores details about the content of the file.
The header usually contains details about the kind of file, the size of the contained image, the number of bits per color, and so on. All these details are required to reproduce the content stored within the file itself.
By inspecting the header, it's possible to confirm the format of the stored data. This requires supporting the specific header format and the Python standard library has support for most common image formats.