Sophie

Sophie

distrib > Mageia > 3 > i586 > media > core-updates > by-pkgid > 50402eac2a16508b365658612a898528 > files > 722

python3-docs-3.3.0-4.3.mga3.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>22.7. imghdr — Determine the type of an image &mdash; Python v3.3.0 documentation</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.3.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v3.3.0 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v3.3.0 documentation" href="../index.html" />
    <link rel="up" title="22. Multimedia Services" href="mm.html" />
    <link rel="next" title="22.8. sndhdr — Determine type of sound file" href="sndhdr.html" />
    <link rel="prev" title="22.6. colorsys — Conversions between color systems" href="colorsys.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="sndhdr.html" title="22.8. sndhdr — Determine type of sound file"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="colorsys.html" title="22.6. colorsys — Conversions between color systems"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li><a href="../index.html">3.3.0 Documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="mm.html" accesskey="U">22. Multimedia Services</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-imghdr">
<span id="imghdr-determine-the-type-of-an-image"></span><h1>22.7. <a class="reference internal" href="#module-imghdr" title="imghdr: Determine the type of image contained in a file or byte stream."><tt class="xref py py-mod docutils literal"><span class="pre">imghdr</span></tt></a> &#8212; Determine the type of an image<a class="headerlink" href="#module-imghdr" title="Permalink to this headline">¶</a></h1>
<p><strong>Source code:</strong> <a class="reference external" href="http://hg.python.org/cpython/file/3.3/Lib/imghdr.py">Lib/imghdr.py</a></p>
<hr class="docutils" />
<p>The <a class="reference internal" href="#module-imghdr" title="imghdr: Determine the type of image contained in a file or byte stream."><tt class="xref py py-mod docutils literal"><span class="pre">imghdr</span></tt></a> module determines the type of image contained in a file or
byte stream.</p>
<p>The <a class="reference internal" href="#module-imghdr" title="imghdr: Determine the type of image contained in a file or byte stream."><tt class="xref py py-mod docutils literal"><span class="pre">imghdr</span></tt></a> module defines the following function:</p>
<dl class="function">
<dt id="imghdr.what">
<tt class="descclassname">imghdr.</tt><tt class="descname">what</tt><big>(</big><em>filename</em>, <em>h=None</em><big>)</big><a class="headerlink" href="#imghdr.what" title="Permalink to this definition">¶</a></dt>
<dd><p>Tests the image data contained in the file named by <em>filename</em>, and returns a
string describing the image type.  If optional <em>h</em> is provided, the <em>filename</em>
is ignored and <em>h</em> is assumed to contain the byte stream to test.</p>
</dd></dl>

<p>The following image types are recognized, as listed below with the return value
from <a class="reference internal" href="#imghdr.what" title="imghdr.what"><tt class="xref py py-func docutils literal"><span class="pre">what()</span></tt></a>:</p>
<table border="1" class="docutils">
<colgroup>
<col width="26%" />
<col width="74%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Value</th>
<th class="head">Image format</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal"><span class="pre">'rgb'</span></tt></td>
<td>SGI ImgLib Files</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'gif'</span></tt></td>
<td>GIF 87a and 89a Files</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'pbm'</span></tt></td>
<td>Portable Bitmap Files</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'pgm'</span></tt></td>
<td>Portable Graymap Files</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'ppm'</span></tt></td>
<td>Portable Pixmap Files</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'tiff'</span></tt></td>
<td>TIFF Files</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'rast'</span></tt></td>
<td>Sun Raster Files</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'xbm'</span></tt></td>
<td>X Bitmap Files</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'jpeg'</span></tt></td>
<td>JPEG data in JFIF or Exif formats</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'bmp'</span></tt></td>
<td>BMP files</td>
</tr>
<tr><td><tt class="docutils literal"><span class="pre">'png'</span></tt></td>
<td>Portable Network Graphics</td>
</tr>
</tbody>
</table>
<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."><tt class="xref py py-mod docutils literal"><span class="pre">imghdr</span></tt></a> can recognize by appending
to this variable:</p>
<dl class="data">
<dt id="imghdr.tests">
<tt class="descclassname">imghdr.</tt><tt class="descname">tests</tt><a class="headerlink" href="#imghdr.tests" title="Permalink to this definition">¶</a></dt>
<dd><p>A list of functions performing the individual tests.  Each function takes two
arguments: the byte-stream and an open file-like object. When <a class="reference internal" href="#imghdr.what" title="imghdr.what"><tt class="xref py py-func docutils literal"><span class="pre">what()</span></tt></a> is
called with a byte-stream, the file-like object will be <tt class="xref docutils literal"><span class="pre">None</span></tt>.</p>
<p>The test function should return a string describing the image type if the test
succeeded, or <tt class="xref docutils literal"><span class="pre">None</span></tt> if it failed.</p>
</dd></dl>

<p>Example:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">imghdr</span>
<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="s">&#39;/tmp/bass.gif&#39;</span><span class="p">)</span>
<span class="go">&#39;gif&#39;</span>
</pre></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="colorsys.html"
                        title="previous chapter">22.6. <tt class="docutils literal docutils literal docutils literal"><span class="pre">colorsys</span></tt> &#8212; Conversions between color systems</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="sndhdr.html"
                        title="next chapter">22.8. <tt class="docutils literal"><span class="pre">sndhdr</span></tt> &#8212; Determine type of sound file</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/imghdr.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="sndhdr.html" title="22.8. sndhdr — Determine type of sound file"
             >next</a> |</li>
        <li class="right" >
          <a href="colorsys.html" title="22.6. colorsys — Conversions between color systems"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li><a href="../index.html">3.3.0 Documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="mm.html" >22. Multimedia Services</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2012, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.  
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Sep 29, 2012.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>

  </body>
</html>