1998-08-10 19:42:37 +00:00
|
|
|
\section{\module{imghdr} ---
|
2000-10-10 17:03:45 +00:00
|
|
|
Determine the type of an image}
|
1998-07-23 17:59:49 +00:00
|
|
|
|
2000-10-10 17:03:45 +00:00
|
|
|
\declaremodule{standard}{imghdr}
|
|
|
|
\modulesynopsis{Determine the type of image contained in a file or
|
|
|
|
byte stream.}
|
1998-07-23 17:59:49 +00:00
|
|
|
|
1996-08-19 22:58:03 +00:00
|
|
|
|
1998-03-14 20:09:15 +00:00
|
|
|
The \module{imghdr} module determines the type of image contained in a
|
1996-08-19 22:58:03 +00:00
|
|
|
file or byte stream.
|
|
|
|
|
1998-03-14 20:09:15 +00:00
|
|
|
The \module{imghdr} module defines the following function:
|
1996-08-19 22:58:03 +00:00
|
|
|
|
|
|
|
|
1998-03-14 20:09:15 +00:00
|
|
|
\begin{funcdesc}{what}{filename\optional{, h}}
|
1996-08-19 22:58:03 +00: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 20:09:15 +00:00
|
|
|
return value from \function{what()}:
|
|
|
|
|
1998-04-11 20:53:03 +00:00
|
|
|
\begin{tableii}{l|l}{code}{Value}{Image format}
|
1998-03-14 20:09:15 +00: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 13:30:01 +00:00
|
|
|
\lineii{'jpeg'}{JPEG data in JFIF format}
|
1998-07-17 19:01:29 +00:00
|
|
|
\lineii{'bmp'}{BMP files}
|
|
|
|
\lineii{'png'}{Portable Network Graphics}
|
1998-03-14 20:09:15 +00:00
|
|
|
\end{tableii}
|
|
|
|
|
|
|
|
You can extend the list of file types \module{imghdr} can recognize by
|
1996-08-19 22:58:03 +00: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 20:09:15 +00:00
|
|
|
When \function{what()} is called with a byte-stream, the file-like
|
1996-08-19 22:58:03 +00: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 06:58:54 +00:00
|
|
|
\begin{verbatim}
|
1996-08-19 22:58:03 +00:00
|
|
|
>>> import imghdr
|
|
|
|
>>> imghdr.what('/tmp/bass.gif')
|
|
|
|
'gif'
|
1998-02-13 06:58:54 +00:00
|
|
|
\end{verbatim}
|