Python imghdr Module
Example
Identify an image type from header bytes (no files needed):
import imghdr
png_header = b"\x89PNG\r\n\x1a\n" + b"0"*24
print(imghdr.what(None, png_header))
Try it Yourself »
Warning: The
imghdr
module is deprecated and slated for removal in Python 3.13.Definition and Usage
The imghdr module determines the type of image contained in a file or by examining a byte stream header.
This can be useful for quick checks, but more robust image libraries are recommended for production use.
Members
Member | Description |
---|---|
what() | Determine the image type from a filename or from a byte buffer. |