1 \section{\module{imghdr
} ---
2 Determine the type of an image
}
4 \declaremodule{standard
}{imghdr
}
5 \modulesynopsis{Determine the type of image contained in a file or
9 The
\module{imghdr
} module determines the type of image contained in a
12 The
\module{imghdr
} module defines the following function:
15 \begin{funcdesc
}{what
}{filename
\optional{, h
}}
16 Tests the image data contained in the file named by
\var{filename
},
17 and returns a string describing the image type. If optional
\var{h
}
18 is provided, the
\var{filename
} is ignored and
\var{h
} is assumed to
19 contain the byte stream to test.
22 The following image types are recognized, as listed below with the
23 return value from
\function{what()
}:
25 \begin{tableii
}{l|l
}{code
}{Value
}{Image format
}
26 \lineii{'rgb'
}{SGI ImgLib Files
}
27 \lineii{'gif'
}{GIF
87a and
89a Files
}
28 \lineii{'pbm'
}{Portable Bitmap Files
}
29 \lineii{'pgm'
}{Portable Graymap Files
}
30 \lineii{'ppm'
}{Portable Pixmap Files
}
31 \lineii{'tiff'
}{TIFF Files
}
32 \lineii{'rast'
}{Sun Raster Files
}
33 \lineii{'xbm'
}{X Bitmap Files
}
34 \lineii{'jpeg'
}{JPEG data in JFIF or Exif formats
}
35 \lineii{'bmp'
}{BMP files
}
36 \lineii{'png'
}{Portable Network Graphics
}
39 \versionadded[Exif detection
]{2.5}
41 You can extend the list of file types
\module{imghdr
} can recognize by
42 appending to this variable:
44 \begin{datadesc
}{tests
}
45 A list of functions performing the individual tests. Each function
46 takes two arguments: the byte-stream and an open file-like object.
47 When
\function{what()
} is called with a byte-stream, the file-like
48 object will be
\code{None
}.
50 The test function should return a string describing the image type if
51 the test succeeded, or
\code{None
} if it failed.
58 >>> imghdr.what('/tmp/bass.gif')