1 \section{\module{imghdr
} ---
2 Determine the type of an image.
}
3 \declaremodule{standard
}{imghdr
}
5 \modulesynopsis{Determine the type of image contained in a file or byte stream.
}
8 The
\module{imghdr
} module determines the type of image contained in a
11 The
\module{imghdr
} module defines the following function:
14 \begin{funcdesc
}{what
}{filename
\optional{, h
}}
15 Tests the image data contained in the file named by
\var{filename
},
16 and returns a string describing the image type. If optional
\var{h
}
17 is provided, the
\var{filename
} is ignored and
\var{h
} is assumed to
18 contain the byte stream to test.
21 The following image types are recognized, as listed below with the
22 return value from
\function{what()
}:
24 \begin{tableii
}{l|l
}{code
}{Value
}{Image format
}
25 \lineii{'rgb'
}{SGI ImgLib Files
}
26 \lineii{'gif'
}{GIF
87a and
89a Files
}
27 \lineii{'pbm'
}{Portable Bitmap Files
}
28 \lineii{'pgm'
}{Portable Graymap Files
}
29 \lineii{'ppm'
}{Portable Pixmap Files
}
30 \lineii{'tiff'
}{TIFF Files
}
31 \lineii{'rast'
}{Sun Raster Files
}
32 \lineii{'xbm'
}{X Bitmap Files
}
33 \lineii{'jpeg'
}{JPEG data in JFIF format
}
34 \lineii{'bmp'
}{BMP files
}
35 \lineii{'png'
}{Portable Network Graphics
}
38 You can extend the list of file types
\module{imghdr
} can recognize by
39 appending to this variable:
41 \begin{datadesc
}{tests
}
42 A list of functions performing the individual tests. Each function
43 takes two arguments: the byte-stream and an open file-like object.
44 When
\function{what()
} is called with a byte-stream, the file-like
45 object will be
\code{None
}.
47 The test function should return a string describing the image type if
48 the test succeeded, or
\code{None
} if it failed.
55 >>> imghdr.what('/tmp/bass.gif')