# cpython-withatomic / Doc / libimghdr.tex

The branch 'legacy-trunk' does not exist.
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \section{Standard module \sectcode{imghdr}} \stmodindex{imghdr} The \code{imghdr} module determines the type of image contained in a file or byte stream. The \code{imghdr} module defines the following function: \renewcommand{\indexsubitem}{(in module imghdr)} \begin{funcdesc}{what}{filename\optional{\, h}} 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 return value from \code{what}: \begin{enumerate} \item[rgb''] SGI ImgLib Files \item[gif''] GIF 87a and 89a Files \item[pbm''] Portable Bitmap Files \item[pgm''] Portable Graymap Files \item[ppm''] Portable Pixmap Files \item[tiff''] TIFF Files \item[rast''] Sun Raster Files \item[xbm''] X Bitmap Files \item[jpeg''] JPEG data in JIFF format \end{enumerate} You can extend the list of file types \code{imghdr} can recognize by 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. When \code{what()} is called with a byte-stream, the file-like 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: \begin{verbatim} >>> import imghdr >>> imghdr.what('/tmp/bass.gif') 'gif' \end{verbatim} 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.