Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-sndhdr.html" /> | |
13 | <link rel="prev" href="module-rgbimg.html" /> | |
14 | <link rel="parent" href="mmedia.html" /> | |
15 | <link rel="next" href="module-sndhdr.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>14.9 imghdr -- Determine the type of an image</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="14.8 rgbimg " | |
25 | href="module-rgbimg.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="14. Multimedia Services" | |
28 | href="mmedia.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="14.10 sndhdr " | |
31 | href="module-sndhdr.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-rgbimg.html">14.8 rgbimg </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="mmedia.html">14. Multimedia Services</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-sndhdr.html">14.10 sndhdr </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0016900000000000000000"> | |
56 | 14.9 <tt class="module">imghdr</tt> -- | |
57 | Determine the type of an image</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-imghdr"></A> | |
62 | ||
63 | <P> | |
64 | The <tt class="module">imghdr</tt> module determines the type of image contained in a | |
65 | file or byte stream. | |
66 | ||
67 | <P> | |
68 | The <tt class="module">imghdr</tt> module defines the following function: | |
69 | ||
70 | <P> | |
71 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
72 | <td><nobr><b><tt id='l2h-4762' xml:id='l2h-4762' class="function">what</tt></b>(</nobr></td> | |
73 | <td><var>filename</var><big>[</big><var>, h</var><big>]</big><var></var>)</td></tr></table></dt> | |
74 | <dd> | |
75 | Tests the image data contained in the file named by <var>filename</var>, | |
76 | and returns a string describing the image type. If optional <var>h</var> | |
77 | is provided, the <var>filename</var> is ignored and <var>h</var> is assumed to | |
78 | contain the byte stream to test. | |
79 | </dl> | |
80 | ||
81 | <P> | |
82 | The following image types are recognized, as listed below with the | |
83 | return value from <tt class="function">what()</tt>: | |
84 | ||
85 | <P> | |
86 | <div class="center"><table class="realtable"> | |
87 | <thead> | |
88 | <tr> | |
89 | <th class="left" >Value</th> | |
90 | <th class="left" >Image format</th> | |
91 | </tr> | |
92 | </thead> | |
93 | <tbody> | |
94 | <tr><td class="left" valign="baseline"><code>'rgb'</code></td> | |
95 | <td class="left" >SGI ImgLib Files</td></tr> | |
96 | <tr><td class="left" valign="baseline"><code>'gif'</code></td> | |
97 | <td class="left" >GIF 87a and 89a Files</td></tr> | |
98 | <tr><td class="left" valign="baseline"><code>'pbm'</code></td> | |
99 | <td class="left" >Portable Bitmap Files</td></tr> | |
100 | <tr><td class="left" valign="baseline"><code>'pgm'</code></td> | |
101 | <td class="left" >Portable Graymap Files</td></tr> | |
102 | <tr><td class="left" valign="baseline"><code>'ppm'</code></td> | |
103 | <td class="left" >Portable Pixmap Files</td></tr> | |
104 | <tr><td class="left" valign="baseline"><code>'tiff'</code></td> | |
105 | <td class="left" >TIFF Files</td></tr> | |
106 | <tr><td class="left" valign="baseline"><code>'rast'</code></td> | |
107 | <td class="left" >Sun Raster Files</td></tr> | |
108 | <tr><td class="left" valign="baseline"><code>'xbm'</code></td> | |
109 | <td class="left" >X Bitmap Files</td></tr> | |
110 | <tr><td class="left" valign="baseline"><code>'jpeg'</code></td> | |
111 | <td class="left" >JPEG data in JFIF format</td></tr> | |
112 | <tr><td class="left" valign="baseline"><code>'bmp'</code></td> | |
113 | <td class="left" >BMP files</td></tr> | |
114 | <tr><td class="left" valign="baseline"><code>'png'</code></td> | |
115 | <td class="left" >Portable Network Graphics</td></tr></tbody> | |
116 | </table></div> | |
117 | ||
118 | <P> | |
119 | You can extend the list of file types <tt class="module">imghdr</tt> can recognize by | |
120 | appending to this variable: | |
121 | ||
122 | <P> | |
123 | <dl><dt><b><tt id='l2h-4763' xml:id='l2h-4763'>tests</tt></b></dt> | |
124 | <dd> | |
125 | A list of functions performing the individual tests. Each function | |
126 | takes two arguments: the byte-stream and an open file-like object. | |
127 | When <tt class="function">what()</tt> is called with a byte-stream, the file-like | |
128 | object will be <code>None</code>. | |
129 | ||
130 | <P> | |
131 | The test function should return a string describing the image type if | |
132 | the test succeeded, or <code>None</code> if it failed. | |
133 | </dd></dl> | |
134 | ||
135 | <P> | |
136 | Example: | |
137 | ||
138 | <P> | |
139 | <div class="verbatim"><pre> | |
140 | >>> import imghdr | |
141 | >>> imghdr.what('/tmp/bass.gif') | |
142 | 'gif' | |
143 | </pre></div> | |
144 | ||
145 | <DIV CLASS="navigation"> | |
146 | <div class='online-navigation'> | |
147 | <p></p><hr /> | |
148 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
149 | <tr> | |
150 | <td class='online-navigation'><a rel="prev" title="14.8 rgbimg " | |
151 | href="module-rgbimg.html"><img src='../icons/previous.png' | |
152 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
153 | <td class='online-navigation'><a rel="parent" title="14. Multimedia Services" | |
154 | href="mmedia.html"><img src='../icons/up.png' | |
155 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
156 | <td class='online-navigation'><a rel="next" title="14.10 sndhdr " | |
157 | href="module-sndhdr.html"><img src='../icons/next.png' | |
158 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
159 | <td align="center" width="100%">Python Library Reference</td> | |
160 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
161 | href="contents.html"><img src='../icons/contents.png' | |
162 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
163 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
164 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
165 | <td class='online-navigation'><a rel="index" title="Index" | |
166 | href="genindex.html"><img src='../icons/index.png' | |
167 | border='0' height='32' alt='Index' width='32' /></A></td> | |
168 | </tr></table> | |
169 | <div class='online-navigation'> | |
170 | <b class="navlabel">Previous:</b> | |
171 | <a class="sectref" rel="prev" href="module-rgbimg.html">14.8 rgbimg </A> | |
172 | <b class="navlabel">Up:</b> | |
173 | <a class="sectref" rel="parent" href="mmedia.html">14. Multimedia Services</A> | |
174 | <b class="navlabel">Next:</b> | |
175 | <a class="sectref" rel="next" href="module-sndhdr.html">14.10 sndhdr </A> | |
176 | </div> | |
177 | </div> | |
178 | <hr /> | |
179 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
180 | </DIV> | |
181 | <!--End of Navigation Panel--> | |
182 | <ADDRESS> | |
183 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
184 | </ADDRESS> | |
185 | </BODY> | |
186 | </HTML> |