1998-04-04 03:23:21 -04:00
|
|
|
\section{Standard Module \module{imghdr}}
|
1997-07-17 13:34:52 -03:00
|
|
|
\label{module-imghdr}
|
1996-08-19 19:58:03 -03:00
|
|
|
\stmodindex{imghdr}
|
|
|
|
|
1998-03-14 16:09:15 -04:00
|
|
|
The \module{imghdr} module determines the type of image contained in a
|
1996-08-19 19:58:03 -03:00
|
|
|
file or byte stream.
|
|
|
|
|
1998-03-14 16:09:15 -04:00
|
|
|
The \module{imghdr} module defines the following function:
|
1996-08-19 19:58:03 -03:00
|
|
|
|
|
|
|
|
1998-03-14 16:09:15 -04:00
|
|
|
\begin{funcdesc}{what}{filename\optional{, h}}
|
1996-08-19 19:58:03 -03:00
|
|
|
Tests the image data contained in the file named by \var{filename},
|
|
|
|
and returns a string describing the image type. If optional \var{h}
|
|
|
|
is provided, the \var{filename} is ignored and \var{h} is assumed to
|
|
|
|
contain the byte stream to test.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
The following image types are recognized, as listed below with the
|
1998-03-14 16:09:15 -04:00
|
|
|
return value from \function{what()}:
|
|
|
|
|
1998-04-11 17:53:03 -03:00
|
|
|
\begin{tableii}{l|l}{code}{Value}{Image format}
|
1998-03-14 16:09:15 -04:00
|
|
|
\lineii{'rgb'}{SGI ImgLib Files}
|
|
|
|
\lineii{'gif'}{GIF 87a and 89a Files}
|
|
|
|
\lineii{'pbm'}{Portable Bitmap Files}
|
|
|
|
\lineii{'pgm'}{Portable Graymap Files}
|
|
|
|
\lineii{'ppm'}{Portable Pixmap Files}
|
|
|
|
\lineii{'tiff'}{TIFF Files}
|
|
|
|
\lineii{'rast'}{Sun Raster Files}
|
|
|
|
\lineii{'xbm'}{X Bitmap Files}
|
|
|
|
\lineii{'jpeg'}{JPEG data in JIFF format}
|
|
|
|
\end{tableii}
|
|
|
|
|
|
|
|
You can extend the list of file types \module{imghdr} can recognize by
|
1996-08-19 19:58:03 -03:00
|
|
|
appending to this variable:
|
|
|
|
|
|
|
|
\begin{datadesc}{tests}
|
|
|
|
A list of functions performing the individual tests. Each function
|
|
|
|
takes two arguments: the byte-stream and an open file-like object.
|
1998-03-14 16:09:15 -04:00
|
|
|
When \function{what()} is called with a byte-stream, the file-like
|
1996-08-19 19:58:03 -03:00
|
|
|
object will be \code{None}.
|
|
|
|
|
|
|
|
The test function should return a string describing the image type if
|
|
|
|
the test succeeded, or \code{None} if it failed.
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
1998-02-13 02:58:54 -04:00
|
|
|
\begin{verbatim}
|
1996-08-19 19:58:03 -03:00
|
|
|
>>> import imghdr
|
|
|
|
>>> imghdr.what('/tmp/bass.gif')
|
|
|
|
'gif'
|
1998-02-13 02:58:54 -04:00
|
|
|
\end{verbatim}
|