1:mod:`imghdr` --- Determine the type of an image
2================================================
3
4.. module:: imghdr
5   :synopsis: Determine the type of image contained in a file or byte stream.
6   :deprecated:
7
8**Source code:** :source:`Lib/imghdr.py`
9
10.. deprecated-removed:: 3.11 3.13
11   The :mod:`imghdr` module is deprecated
12   (see :pep:`PEP 594 <594#imghdr>` for details and alternatives).
13
14--------------
15
16The :mod:`imghdr` module determines the type of image contained in a file or
17byte stream.
18
19The :mod:`imghdr` module defines the following function:
20
21
22.. function:: what(file, h=None)
23
24   Tests the image data contained in the file named by *file*, and returns a
25   string describing the image type.  If optional *h* is provided, the *file*
26   argument is ignored and *h* is assumed to contain the byte stream to test.
27
28   .. versionchanged:: 3.6
29      Accepts a :term:`path-like object`.
30
31The following image types are recognized, as listed below with the return value
32from :func:`what`:
33
34+------------+-----------------------------------+
35| Value      | Image format                      |
36+============+===================================+
37| ``'rgb'``  | SGI ImgLib Files                  |
38+------------+-----------------------------------+
39| ``'gif'``  | GIF 87a and 89a Files             |
40+------------+-----------------------------------+
41| ``'pbm'``  | Portable Bitmap Files             |
42+------------+-----------------------------------+
43| ``'pgm'``  | Portable Graymap Files            |
44+------------+-----------------------------------+
45| ``'ppm'``  | Portable Pixmap Files             |
46+------------+-----------------------------------+
47| ``'tiff'`` | TIFF Files                        |
48+------------+-----------------------------------+
49| ``'rast'`` | Sun Raster Files                  |
50+------------+-----------------------------------+
51| ``'xbm'``  | X Bitmap Files                    |
52+------------+-----------------------------------+
53| ``'jpeg'`` | JPEG data in JFIF or Exif formats |
54+------------+-----------------------------------+
55| ``'bmp'``  | BMP files                         |
56+------------+-----------------------------------+
57| ``'png'``  | Portable Network Graphics         |
58+------------+-----------------------------------+
59| ``'webp'`` | WebP files                        |
60+------------+-----------------------------------+
61| ``'exr'``  | OpenEXR Files                     |
62+------------+-----------------------------------+
63
64.. versionadded:: 3.5
65   The *exr* and *webp* formats were added.
66
67
68You can extend the list of file types :mod:`imghdr` can recognize by appending
69to this variable:
70
71
72.. data:: tests
73
74   A list of functions performing the individual tests.  Each function takes two
75   arguments: the byte-stream and an open file-like object. When :func:`what` is
76   called with a byte-stream, the file-like object will be ``None``.
77
78   The test function should return a string describing the image type if the test
79   succeeded, or ``None`` if it failed.
80
81Example::
82
83   >>> import imghdr
84   >>> imghdr.what('bass.gif')
85   'gif'
86
87