source: vendor/python/2.5/Doc/lib/libimghdr.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 1.8 KB
Line 
1\section{\module{imghdr} ---
2 Determine the type of an image}
3
4\declaremodule{standard}{imghdr}
5\modulesynopsis{Determine the type of image contained in a file or
6 byte stream.}
7
8
9The \module{imghdr} module determines the type of image contained in a
10file or byte stream.
11
12The \module{imghdr} module defines the following function:
13
14
15\begin{funcdesc}{what}{filename\optional{, h}}
16Tests the image data contained in the file named by \var{filename},
17and returns a string describing the image type. If optional \var{h}
18is provided, the \var{filename} is ignored and \var{h} is assumed to
19contain the byte stream to test.
20\end{funcdesc}
21
22The following image types are recognized, as listed below with the
23return value from \function{what()}:
24
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}
37\end{tableii}
38
39\versionadded[Exif detection]{2.5}
40
41You can extend the list of file types \module{imghdr} can recognize by
42appending to this variable:
43
44\begin{datadesc}{tests}
45A list of functions performing the individual tests. Each function
46takes two arguments: the byte-stream and an open file-like object.
47When \function{what()} is called with a byte-stream, the file-like
48object will be \code{None}.
49
50The test function should return a string describing the image type if
51the test succeeded, or \code{None} if it failed.
52\end{datadesc}
53
54Example:
55
56\begin{verbatim}
57>>> import imghdr
58>>> imghdr.what('/tmp/bass.gif')
59'gif'
60\end{verbatim}
Note: See TracBrowser for help on using the repository browser.