1998-08-10 16:42:37 -03:00
|
|
|
\section{\module{imghdr} ---
|
|
|
|
Determine the type of image contained in a file or byte stream.}
|
1998-07-23 14:59:49 -03:00
|
|
|
\declaremodule{standard}{imghdr}
|
|
|
|
|
|
|
|
\modulesynopsis{Determine the type of image contained in a file or byte stream.}
|
|
|
|
|
1996-08-19 19:58:03 -03:00
|
|
|
|
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}
|
1998-10-19 10:30:01 -03:00
|
|
|
\lineii{'jpeg'}{JPEG data in JFIF format}
|
1998-07-17 16:01:29 -03:00
|
|
|
\lineii{'bmp'}{BMP files}
|
|
|
|
\lineii{'png'}{Portable Network Graphics}
|
1998-03-14 16:09:15 -04:00
|
|
|
\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}
|