Theimghdr module determines the type of image contained in afile or byte stream.
Theimghdr module defines the following function:
The following image types are recognized, as listed below with thereturn value fromwhat():
| Value | Image format |
|---|---|
'rgb' | SGI ImgLib Files |
'gif' | GIF 87a and 89a Files |
'pbm' | Portable Bitmap Files |
'pgm' | Portable Graymap Files |
'ppm' | Portable Pixmap Files |
'tiff' | TIFF Files |
'rast' | Sun Raster Files |
'xbm' | X Bitmap Files |
'jpeg' | JPEG data in JFIF format |
'bmp' | BMP files |
'png' | Portable Network Graphics |
You can extend the list of file typesimghdr can recognize byappending to this variable:
None.The test function should return a string describing the image type ifthe test succeeded, orNone if it failed.
Example:
>>> import imghdr>>> imghdr.what('/tmp/bass.gif')'gif'| Python Library Reference |