Source

cpython_sandbox / Doc / library / imghdr.rst

Full commit

:mod:`imghdr` --- Determine the type of an image

Source code: :source:`Lib/imghdr.py`


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

The :mod:`imghdr` module defines the following function:

The following image types are recognized, as listed below with the return value from :func:`what`:

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 or Exif formats
'bmp' BMP files
'png' Portable Network Graphics

You can extend the list of file types :mod:`imghdr` can recognize by appending to this variable:

Example:

>>> import imghdr
>>> imghdr.what('bass.gif')
'gif'