annotate Doc/lib/libimghdr.tex @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 3e6863cea383
children 3468ea8645ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4047
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 \section{Standard module \sectcode{imghdr}}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 \stmodindex{imghdr}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 The \code{imghdr} module determines the type of image contained in a
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 file or byte stream.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 The \code{imghdr} module defines the following function:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 \renewcommand{\indexsubitem}{(in module imghdr)}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 \begin{funcdesc}{what}{filename\optional{\, h}}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Tests the image data contained in the file named by \var{filename},
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 and returns a string describing the image type. If optional \var{h}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 is provided, the \var{filename} is ignored and \var{h} is assumed to
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 contain the byte stream to test.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 The following image types are recognized, as listed below with the
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 return value from \code{what}:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 \begin{enumerate}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 \item[``rgb''] SGI ImgLib Files
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 \item[``gif''] GIF 87a and 89a Files
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 \item[``pbm''] Portable Bitmap Files
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 \item[``pgm''] Portable Graymap Files
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 \item[``ppm''] Portable Pixmap Files
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 \item[``tiff''] TIFF Files
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 \item[``rast''] Sun Raster Files
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 \item[``xbm''] X Bitmap Files
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 \item[``jpeg''] JPEG data in JIFF format
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 \end{enumerate}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 You can extend the list of file types \code{imghdr} can recognize by
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 appending to this variable:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 \begin{datadesc}{tests}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 A list of functions performing the individual tests. Each function
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 takes two arguments: the byte-stream and an open file-like object.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 When \code{what()} is called with a byte-stream, the file-like
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 object will be \code{None}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 The test function should return a string describing the image type if
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 the test succeeded, or \code{None} if it failed.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 \end{datadesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 Example:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 \begin{verbatim}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 >>> import imghdr
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 >>> imghdr.what('/tmp/bass.gif')
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 'gif'
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 \end{verbatim}