~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-2.7.11-docs-html/library/imghdr.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
 
 
4
 
 
5
 
<html xmlns="http://www.w3.org/1999/xhtml">
6
 
  <head>
7
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
 
    
9
 
    <title>21.8. imghdr — Determine the type of an image &mdash; Python 2.7.11 documentation</title>
10
 
    
11
 
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
12
 
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
 
    
14
 
    <script type="text/javascript">
15
 
      var DOCUMENTATION_OPTIONS = {
16
 
        URL_ROOT:    '../',
17
 
        VERSION:     '2.7.11',
18
 
        COLLAPSE_INDEX: false,
19
 
        FILE_SUFFIX: '.html',
20
 
        HAS_SOURCE:  true
21
 
      };
22
 
    </script>
23
 
    <script type="text/javascript" src="../_static/jquery.js"></script>
24
 
    <script type="text/javascript" src="../_static/underscore.js"></script>
25
 
    <script type="text/javascript" src="../_static/doctools.js"></script>
26
 
    <script type="text/javascript" src="../_static/sidebar.js"></script>
27
 
    <link rel="search" type="application/opensearchdescription+xml"
28
 
          title="Search within Python 2.7.11 documentation"
29
 
          href="../_static/opensearch.xml"/>
30
 
    <link rel="author" title="About these documents" href="../about.html" />
31
 
    <link rel="copyright" title="Copyright" href="../copyright.html" />
32
 
    <link rel="top" title="Python 2.7.11 documentation" href="../contents.html" />
33
 
    <link rel="up" title="21. Multimedia Services" href="mm.html" />
34
 
    <link rel="next" title="21.9. sndhdr — Determine type of sound file" href="sndhdr.html" />
35
 
    <link rel="prev" title="21.7. colorsys — Conversions between color systems" href="colorsys.html" />
36
 
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
 
    <script type="text/javascript" src="../_static/copybutton.js"></script>
38
 
    <script type="text/javascript" src="../_static/version_switch.js"></script>
39
 
 
40
 
    
41
 
 
42
 
  </head>
43
 
  <body role="document">  
44
 
    <div class="related" role="navigation" aria-label="related navigation">
45
 
      <h3>Navigation</h3>
46
 
      <ul>
47
 
        <li class="right" style="margin-right: 10px">
48
 
          <a href="../genindex.html" title="General Index"
49
 
             accesskey="I">index</a></li>
50
 
        <li class="right" >
51
 
          <a href="../py-modindex.html" title="Python Module Index"
52
 
             >modules</a> |</li>
53
 
        <li class="right" >
54
 
          <a href="sndhdr.html" title="21.9. sndhdr — Determine type of sound file"
55
 
             accesskey="N">next</a> |</li>
56
 
        <li class="right" >
57
 
          <a href="colorsys.html" title="21.7. colorsys — Conversions between color systems"
58
 
             accesskey="P">previous</a> |</li>
59
 
        <li><img src="../_static/py.png" alt=""
60
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
61
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
62
 
        <li>
63
 
          <span class="version_switcher_placeholder">2.7.11</span>
64
 
          <a href="../index.html">Documentation</a> &raquo;
65
 
        </li>
66
 
 
67
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
68
 
          <li class="nav-item nav-item-2"><a href="mm.html" accesskey="U">21. Multimedia Services</a> &raquo;</li> 
69
 
      </ul>
70
 
    </div>    
71
 
 
72
 
    <div class="document">
73
 
      <div class="documentwrapper">
74
 
        <div class="bodywrapper">
75
 
          <div class="body" role="main">
76
 
            
77
 
  <div class="section" id="module-imghdr">
78
 
<span id="imghdr-determine-the-type-of-an-image"></span><h1>21.8. <a class="reference internal" href="#module-imghdr" title="imghdr: Determine the type of image contained in a file or byte stream."><code class="xref py py-mod docutils literal"><span class="pre">imghdr</span></code></a> &#8212; Determine the type of an image<a class="headerlink" href="#module-imghdr" title="Permalink to this headline">¶</a></h1>
79
 
<p><strong>Source code:</strong> <a class="reference external" href="https://hg.python.org/cpython/file/2.7/Lib/imghdr.py">Lib/imghdr.py</a></p>
80
 
<hr class="docutils" />
81
 
<p>The <a class="reference internal" href="#module-imghdr" title="imghdr: Determine the type of image contained in a file or byte stream."><code class="xref py py-mod docutils literal"><span class="pre">imghdr</span></code></a> module determines the type of image contained in a file or
82
 
byte stream.</p>
83
 
<p>The <a class="reference internal" href="#module-imghdr" title="imghdr: Determine the type of image contained in a file or byte stream."><code class="xref py py-mod docutils literal"><span class="pre">imghdr</span></code></a> module defines the following function:</p>
84
 
<dl class="function">
85
 
<dt id="imghdr.what">
86
 
<code class="descclassname">imghdr.</code><code class="descname">what</code><span class="sig-paren">(</span><em>filename</em><span class="optional">[</span>, <em>h</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imghdr.what" title="Permalink to this definition">¶</a></dt>
87
 
<dd><p>Tests the image data contained in the file named by <em>filename</em>, and returns a
88
 
string describing the image type.  If optional <em>h</em> is provided, the <em>filename</em>
89
 
is ignored and <em>h</em> is assumed to contain the byte stream to test.</p>
90
 
</dd></dl>
91
 
 
92
 
<p>The following image types are recognized, as listed below with the return value
93
 
from <a class="reference internal" href="#imghdr.what" title="imghdr.what"><code class="xref py py-func docutils literal"><span class="pre">what()</span></code></a>:</p>
94
 
<table border="1" class="docutils">
95
 
<colgroup>
96
 
<col width="26%" />
97
 
<col width="74%" />
98
 
</colgroup>
99
 
<thead valign="bottom">
100
 
<tr class="row-odd"><th class="head">Value</th>
101
 
<th class="head">Image format</th>
102
 
</tr>
103
 
</thead>
104
 
<tbody valign="top">
105
 
<tr class="row-even"><td><code class="docutils literal"><span class="pre">'rgb'</span></code></td>
106
 
<td>SGI ImgLib Files</td>
107
 
</tr>
108
 
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">'gif'</span></code></td>
109
 
<td>GIF 87a and 89a Files</td>
110
 
</tr>
111
 
<tr class="row-even"><td><code class="docutils literal"><span class="pre">'pbm'</span></code></td>
112
 
<td>Portable Bitmap Files</td>
113
 
</tr>
114
 
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">'pgm'</span></code></td>
115
 
<td>Portable Graymap Files</td>
116
 
</tr>
117
 
<tr class="row-even"><td><code class="docutils literal"><span class="pre">'ppm'</span></code></td>
118
 
<td>Portable Pixmap Files</td>
119
 
</tr>
120
 
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">'tiff'</span></code></td>
121
 
<td>TIFF Files</td>
122
 
</tr>
123
 
<tr class="row-even"><td><code class="docutils literal"><span class="pre">'rast'</span></code></td>
124
 
<td>Sun Raster Files</td>
125
 
</tr>
126
 
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">'xbm'</span></code></td>
127
 
<td>X Bitmap Files</td>
128
 
</tr>
129
 
<tr class="row-even"><td><code class="docutils literal"><span class="pre">'jpeg'</span></code></td>
130
 
<td>JPEG data in JFIF or Exif formats</td>
131
 
</tr>
132
 
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">'bmp'</span></code></td>
133
 
<td>BMP files</td>
134
 
</tr>
135
 
<tr class="row-even"><td><code class="docutils literal"><span class="pre">'png'</span></code></td>
136
 
<td>Portable Network Graphics</td>
137
 
</tr>
138
 
</tbody>
139
 
</table>
140
 
<div class="versionadded">
141
 
<p><span class="versionmodified">New in version 2.5: </span>Exif detection.</p>
142
 
</div>
143
 
<p>You can extend the list of file types <a class="reference internal" href="#module-imghdr" title="imghdr: Determine the type of image contained in a file or byte stream."><code class="xref py py-mod docutils literal"><span class="pre">imghdr</span></code></a> can recognize by appending
144
 
to this variable:</p>
145
 
<dl class="data">
146
 
<dt id="imghdr.tests">
147
 
<code class="descclassname">imghdr.</code><code class="descname">tests</code><a class="headerlink" href="#imghdr.tests" title="Permalink to this definition">¶</a></dt>
148
 
<dd><p>A list of functions performing the individual tests.  Each function takes two
149
 
arguments: the byte-stream and an open file-like object. When <a class="reference internal" href="#imghdr.what" title="imghdr.what"><code class="xref py py-func docutils literal"><span class="pre">what()</span></code></a> is
150
 
called with a byte-stream, the file-like object will be <code class="docutils literal"><span class="pre">None</span></code>.</p>
151
 
<p>The test function should return a string describing the image type if the test
152
 
succeeded, or <code class="docutils literal"><span class="pre">None</span></code> if it failed.</p>
153
 
</dd></dl>
154
 
 
155
 
<p>Example:</p>
156
 
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">imghdr</span>
157
 
<span class="gp">&gt;&gt;&gt; </span><span class="n">imghdr</span><span class="o">.</span><span class="n">what</span><span class="p">(</span><span class="s1">&#39;bass.gif&#39;</span><span class="p">)</span>
158
 
<span class="go">&#39;gif&#39;</span>
159
 
</pre></div>
160
 
</div>
161
 
</div>
162
 
 
163
 
 
164
 
          </div>
165
 
        </div>
166
 
      </div>
167
 
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
168
 
        <div class="sphinxsidebarwrapper">
169
 
  <h4>Previous topic</h4>
170
 
  <p class="topless"><a href="colorsys.html"
171
 
                        title="previous chapter">21.7. <code class="docutils literal"><span class="pre">colorsys</span></code> &#8212; Conversions between color systems</a></p>
172
 
  <h4>Next topic</h4>
173
 
  <p class="topless"><a href="sndhdr.html"
174
 
                        title="next chapter">21.9. <code class="docutils literal"><span class="pre">sndhdr</span></code> &#8212; Determine type of sound file</a></p>
175
 
<h3>This Page</h3>
176
 
<ul class="this-page-menu">
177
 
  <li><a href="../bugs.html">Report a Bug</a></li>
178
 
  <li><a href="../_sources/library/imghdr.txt"
179
 
         rel="nofollow">Show Source</a></li>
180
 
</ul>
181
 
 
182
 
<div id="searchbox" style="display: none" role="search">
183
 
  <h3>Quick search</h3>
184
 
    <form class="search" action="../search.html" method="get">
185
 
      <input type="text" name="q" />
186
 
      <input type="submit" value="Go" />
187
 
      <input type="hidden" name="check_keywords" value="yes" />
188
 
      <input type="hidden" name="area" value="default" />
189
 
    </form>
190
 
    <p class="searchtip" style="font-size: 90%">
191
 
    Enter search terms or a module, class or function name.
192
 
    </p>
193
 
</div>
194
 
<script type="text/javascript">$('#searchbox').show(0);</script>
195
 
        </div>
196
 
      </div>
197
 
      <div class="clearer"></div>
198
 
    </div>  
199
 
    <div class="related" role="navigation" aria-label="related navigation">
200
 
      <h3>Navigation</h3>
201
 
      <ul>
202
 
        <li class="right" style="margin-right: 10px">
203
 
          <a href="../genindex.html" title="General Index"
204
 
             >index</a></li>
205
 
        <li class="right" >
206
 
          <a href="../py-modindex.html" title="Python Module Index"
207
 
             >modules</a> |</li>
208
 
        <li class="right" >
209
 
          <a href="sndhdr.html" title="21.9. sndhdr — Determine type of sound file"
210
 
             >next</a> |</li>
211
 
        <li class="right" >
212
 
          <a href="colorsys.html" title="21.7. colorsys — Conversions between color systems"
213
 
             >previous</a> |</li>
214
 
        <li><img src="../_static/py.png" alt=""
215
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
216
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
217
 
        <li>
218
 
          <span class="version_switcher_placeholder">2.7.11</span>
219
 
          <a href="../index.html">Documentation</a> &raquo;
220
 
        </li>
221
 
 
222
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
223
 
          <li class="nav-item nav-item-2"><a href="mm.html" >21. Multimedia Services</a> &raquo;</li> 
224
 
      </ul>
225
 
    </div>  
226
 
    <div class="footer">
227
 
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
228
 
    <br />
229
 
    The Python Software Foundation is a non-profit corporation.
230
 
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
231
 
    <br />
232
 
    Last updated on Jan 23, 2016.
233
 
    <a href="../bugs.html">Found a bug</a>?
234
 
    <br />
235
 
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
236
 
    </div>
237
 
 
238
 
  </body>
239
 
</html>
 
 
b'\\ No newline at end of file'