Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > b17ed897c34853a0a39ef25ab5d3af32 > files > 105

python3-pillow-doc-2.6.2-2.mga5.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>Image file formats &mdash; Pillow v2.6.2 (PIL fork)</title>
    
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.2',
        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>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="top" title="Pillow v2.6.2 (PIL fork)" href="../index.html" />
    <link rel="up" title="Appendices" href="appendices.html" />
    <link rel="next" title="Writing your own file decoder" href="writing-your-own-file-decoder.html" />
    <link rel="prev" title="Appendices" href="appendices.html" /> 
  </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="writing-your-own-file-decoder.html" title="Writing your own file decoder"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="appendices.html" title="Appendices"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">Home</a> &raquo;</li>
          <li><a href="appendices.html" accesskey="U">Appendices</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="image-file-formats">
<span id="id1"></span><h1>Image file formats<a class="headerlink" href="#image-file-formats" title="Permalink to this headline">¶</a></h1>
<p>The Python Imaging Library supports a wide variety of raster file formats.
Nearly 30 different file formats can be identified and read by the library.
Write support is less extensive, but most common interchange and presentation
formats are supported.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> function identifies files from their
contents, not their names, but the <tt class="xref py py-meth docutils literal"><span class="pre">save()</span></tt> method
looks at the name to determine which format to use, unless the format is given
explicitly.</p>
<div class="section" id="fully-supported-formats">
<h2>Fully supported formats<a class="headerlink" href="#fully-supported-formats" title="Permalink to this headline">¶</a></h2>
<div class="section" id="bmp">
<h3>BMP<a class="headerlink" href="#bmp" title="Permalink to this headline">¶</a></h3>
<p>PIL reads and writes Windows and OS/2 BMP files containing <tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">L</span></tt>, <tt class="docutils literal"><span class="pre">P</span></tt>,
or <tt class="docutils literal"><span class="pre">RGB</span></tt> data. 16-colour images are read as <tt class="docutils literal"><span class="pre">P</span></tt> images. Run-length encoding
is not supported.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> properties:</p>
<dl class="docutils">
<dt><strong>compression</strong></dt>
<dd>Set to <tt class="docutils literal"><span class="pre">bmp_rle</span></tt> if the file is run-length encoded.</dd>
</dl>
</div>
<div class="section" id="eps">
<h3>EPS<a class="headerlink" href="#eps" title="Permalink to this headline">¶</a></h3>
<p>PIL identifies EPS files containing image data, and can read files that contain
embedded raster images (ImageData descriptors). If Ghostscript is available,
other EPS files can be read as well. The EPS driver can also write EPS images.</p>
<p>If Ghostscript is available, you can call the <tt class="xref py py-meth docutils literal"><span class="pre">load()</span></tt>
method with the following parameter to affect how Ghostscript renders the EPS</p>
<dl class="docutils">
<dt><strong>scale</strong></dt>
<dd><p class="first">Affects the scale of the resultant rasterized image. If the EPS suggests
that the image be rendered at 100px x 100px, setting this parameter to
2 will make the Ghostscript render a 200px x 200px image instead. The
relative position of the bounding box is maintained:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">im</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="n">im</span><span class="o">.</span><span class="n">size</span> <span class="c">#(100,100)</span>
<span class="n">im</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">scale</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="n">im</span><span class="o">.</span><span class="n">size</span> <span class="c">#(200,200)</span>
</pre></div>
</div>
</dd>
</dl>
</div>
<div class="section" id="gif">
<h3>GIF<a class="headerlink" href="#gif" title="Permalink to this headline">¶</a></h3>
<p>PIL reads GIF87a and GIF89a versions of the GIF file format. The library writes
run-length encoded GIF87a files. Note that GIF files are always read as
grayscale (<tt class="docutils literal"><span class="pre">L</span></tt>) or palette mode (<tt class="docutils literal"><span class="pre">P</span></tt>) images.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> properties:</p>
<dl class="docutils">
<dt><strong>background</strong></dt>
<dd>Default background color (a palette color index).</dd>
<dt><strong>duration</strong></dt>
<dd>Time between frames in an animation (in milliseconds).</dd>
<dt><strong>transparency</strong></dt>
<dd>Transparency color index. This key is omitted if the image is not
transparent.</dd>
<dt><strong>version</strong></dt>
<dd>Version (either <tt class="docutils literal"><span class="pre">GIF87a</span></tt> or <tt class="docutils literal"><span class="pre">GIF89a</span></tt>).</dd>
</dl>
<div class="section" id="reading-sequences">
<h4>Reading sequences<a class="headerlink" href="#reading-sequences" title="Permalink to this headline">¶</a></h4>
<p>The GIF loader supports the <a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.seek" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">seek()</span></tt></a> and <a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.tell" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">tell()</span></tt></a>
methods. You can seek to the next frame (<tt class="docutils literal"><span class="pre">im.seek(im.tell()</span> <span class="pre">+</span> <span class="pre">1</span></tt>), or rewind
the file by seeking to the first frame. Random access is not supported.</p>
</div>
<div class="section" id="reading-local-images">
<h4>Reading local images<a class="headerlink" href="#reading-local-images" title="Permalink to this headline">¶</a></h4>
<p>The GIF loader creates an image memory the same size as the GIF file’s <em>logical
screen size</em>, and pastes the actual pixel data (the <em>local image</em>) into this
image. If you only want the actual pixel rectangle, you can manipulate the
<tt class="xref py py-attr docutils literal"><span class="pre">size</span></tt> and <tt class="xref py py-attr docutils literal"><span class="pre">tile</span></tt>
attributes before loading the file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">im</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>

<span class="k">if</span> <span class="n">im</span><span class="o">.</span><span class="n">tile</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;gif&quot;</span><span class="p">:</span>
    <span class="c"># only read the first &quot;local image&quot; from this GIF file</span>
    <span class="n">tag</span><span class="p">,</span> <span class="p">(</span><span class="n">x0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">y1</span><span class="p">),</span> <span class="n">offset</span><span class="p">,</span> <span class="n">extra</span> <span class="o">=</span> <span class="n">im</span><span class="o">.</span><span class="n">tile</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">im</span><span class="o">.</span><span class="n">size</span> <span class="o">=</span> <span class="p">(</span><span class="n">x1</span> <span class="o">-</span> <span class="n">x0</span><span class="p">,</span> <span class="n">y1</span> <span class="o">-</span> <span class="n">y0</span><span class="p">)</span>
    <span class="n">im</span><span class="o">.</span><span class="n">tile</span> <span class="o">=</span> <span class="p">[(</span><span class="n">tag</span><span class="p">,</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="n">im</span><span class="o">.</span><span class="n">size</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">extra</span><span class="p">)]</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="im">
<h3>IM<a class="headerlink" href="#im" title="Permalink to this headline">¶</a></h3>
<p>IM is a format used by LabEye and other applications based on the IFUNC image
processing library. The library reads and writes most uncompressed interchange
versions of this format.</p>
<p>IM is the only format that can store all internal PIL formats.</p>
</div>
<div class="section" id="jpeg">
<h3>JPEG<a class="headerlink" href="#jpeg" title="Permalink to this headline">¶</a></h3>
<p>PIL reads JPEG, JFIF, and Adobe JPEG files containing <tt class="docutils literal"><span class="pre">L</span></tt>, <tt class="docutils literal"><span class="pre">RGB</span></tt>, or
<tt class="docutils literal"><span class="pre">CMYK</span></tt> data. It writes standard and progressive JFIF files.</p>
<p>Using the <tt class="xref py py-meth docutils literal"><span class="pre">draft()</span></tt> method, you can speed things up by
converting <tt class="docutils literal"><span class="pre">RGB</span></tt> images to <tt class="docutils literal"><span class="pre">L</span></tt>, and resize images to 1/2, 1/4 or 1/8 of
their original size while loading them. The <tt class="xref py py-meth docutils literal"><span class="pre">draft()</span></tt>
method also configures the JPEG decoder to trade some quality for speed.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method may set the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> properties if available:</p>
<dl class="docutils">
<dt><strong>jfif</strong></dt>
<dd>JFIF application marker found. If the file is not a JFIF file, this key is
not present.</dd>
<dt><strong>jfif_version</strong></dt>
<dd>A tuple representing the jfif version, (major version, minor version).</dd>
<dt><strong>jfif_density</strong></dt>
<dd>A tuple representing the pixel density of the image, in units specified
by jfif_unit.</dd>
<dt><strong>jfif_unit</strong></dt>
<dd><p class="first">Units for the jfif_density:</p>
<ul class="last simple">
<li>0 - No Units</li>
<li>1 - Pixels per Inch</li>
<li>2 - Pixels per Centimeter</li>
</ul>
</dd>
<dt><strong>dpi</strong></dt>
<dd>A tuple representing the reported pixel density in pixels per inch, if
the file is a jfif file and the units are in inches.</dd>
<dt><strong>adobe</strong></dt>
<dd>Adobe application marker found. If the file is not an Adobe JPEG file, this
key is not present.</dd>
<dt><strong>adobe_transform</strong></dt>
<dd>Vendor Specific Tag.</dd>
<dt><strong>progression</strong></dt>
<dd>Indicates that this is a progressive JPEG file.</dd>
<dt><strong>icc-profile</strong></dt>
<dd>The ICC color profile for the image.</dd>
<dt><strong>exif</strong></dt>
<dd>Raw EXIF data from the image.</dd>
</dl>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">save()</span></tt> method supports the following options:</p>
<dl class="docutils">
<dt><strong>quality</strong></dt>
<dd>The image quality, on a scale from 1 (worst) to 95 (best). The default is
75. Values above 95 should be avoided; 100 disables portions of the JPEG
compression algorithm, and results in large files with hardly any gain in
image quality.</dd>
<dt><strong>optimize</strong></dt>
<dd>If present, indicates that the encoder should make an extra pass over the
image in order to select optimal encoder settings.</dd>
<dt><strong>progressive</strong></dt>
<dd>If present, indicates that this image should be stored as a progressive
JPEG file.</dd>
<dt><strong>dpi</strong></dt>
<dd>A tuple of integers representing the pixel density, <tt class="docutils literal"><span class="pre">(x,y)</span></tt>.</dd>
<dt><strong>icc-profile</strong></dt>
<dd><p class="first">If present, the image is stored with the provided ICC profile. If
this parameter is not provided, the image will be saved with no
profile attached. To preserve the existing profile:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">im</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s">&#39;jpeg&#39;</span><span class="p">,</span> <span class="n">icc_profile</span><span class="o">=</span><span class="n">im</span><span class="o">.</span><span class="n">info</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;icc_profile&#39;</span><span class="p">))</span>
</pre></div>
</div>
</dd>
<dt><strong>exif</strong></dt>
<dd>If present, the image will be stored with the provided raw EXIF data.</dd>
<dt><strong>subsampling</strong></dt>
<dd><p class="first">If present, sets the subsampling for the encoder.</p>
<ul class="last simple">
<li><tt class="docutils literal"><span class="pre">keep</span></tt>: Only valid for JPEG files, will retain the original image setting.</li>
<li><tt class="docutils literal"><span class="pre">4:4:4</span></tt>, <tt class="docutils literal"><span class="pre">4:2:2</span></tt>, <tt class="docutils literal"><span class="pre">4:1:1</span></tt>: Specific sampling values</li>
<li><tt class="docutils literal"><span class="pre">-1</span></tt>: equivalent to <tt class="docutils literal"><span class="pre">keep</span></tt></li>
<li><tt class="docutils literal"><span class="pre">0</span></tt>: equivalent to <tt class="docutils literal"><span class="pre">4:4:4</span></tt></li>
<li><tt class="docutils literal"><span class="pre">1</span></tt>: equivalent to <tt class="docutils literal"><span class="pre">4:2:2</span></tt></li>
<li><tt class="docutils literal"><span class="pre">2</span></tt>: equivalent to <tt class="docutils literal"><span class="pre">4:1:1</span></tt></li>
</ul>
</dd>
<dt><strong>qtables</strong></dt>
<dd><p class="first">If present, sets the qtables for the encoder. This is listed as an
advanced option for wizards in the JPEG documentation. Use with
caution. <tt class="docutils literal"><span class="pre">qtables</span></tt> can be one of several types of values:</p>
<ul class="simple">
<li>a string, naming a preset, e.g. <tt class="docutils literal"><span class="pre">keep</span></tt>, <tt class="docutils literal"><span class="pre">web_low</span></tt>, or <tt class="docutils literal"><span class="pre">web_high</span></tt></li>
<li>a list, tuple, or dictionary (with integer keys =
range(len(keys))) of lists of 64 integers. There must be
between 2 and 4 tables.</li>
</ul>
<div class="last versionadded">
<p><span class="versionmodified">New in version 2.5.0.</span></p>
</div>
</dd>
</dl>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">To enable JPEG support, you need to build and install the IJG JPEG library
before building the Python Imaging Library. See the distribution README for
details.</p>
</div>
</div>
<div class="section" id="jpeg-2000">
<h3>JPEG 2000<a class="headerlink" href="#jpeg-2000" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.4.0.</span></p>
</div>
<p>PIL reads and writes JPEG 2000 files containing <tt class="docutils literal"><span class="pre">L</span></tt>, <tt class="docutils literal"><span class="pre">LA</span></tt>, <tt class="docutils literal"><span class="pre">RGB</span></tt> or
<tt class="docutils literal"><span class="pre">RGBA</span></tt> data.  It can also read files containing <tt class="docutils literal"><span class="pre">YCbCr</span></tt> data, which it
converts on read into <tt class="docutils literal"><span class="pre">RGB</span></tt> or <tt class="docutils literal"><span class="pre">RGBA</span></tt> depending on whether or not there is
an alpha channel.  PIL supports JPEG 2000 raw codestreams (<tt class="docutils literal"><span class="pre">.j2k</span></tt> files), as
well as boxed JPEG 2000 files (<tt class="docutils literal"><span class="pre">.j2p</span></tt> or <tt class="docutils literal"><span class="pre">.jpx</span></tt> files).  PIL does <em>not</em>
support files whose components have different sampling frequencies.</p>
<p>When loading, if you set the <tt class="docutils literal"><span class="pre">mode</span></tt> on the image prior to the
<tt class="xref py py-meth docutils literal"><span class="pre">load()</span></tt> method being invoked, you can ask PIL to
convert the image to either <tt class="docutils literal"><span class="pre">RGB</span></tt> or <tt class="docutils literal"><span class="pre">RGBA</span></tt> rather than choosing for
itself.  It is also possible to set <tt class="docutils literal"><span class="pre">reduce</span></tt> to the number of resolutions to
discard (each one reduces the size of the resulting image by a factor of 2),
and <tt class="docutils literal"><span class="pre">layers</span></tt> to specify the number of quality layers to load.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">save()</span></tt> method supports the following options:</p>
<dl class="docutils">
<dt><strong>offset</strong></dt>
<dd>The image offset, as a tuple of integers, e.g. (16, 16)</dd>
<dt><strong>tile_offset</strong></dt>
<dd>The tile offset, again as a 2-tuple of integers.</dd>
<dt><strong>tile_size</strong></dt>
<dd>The tile size as a 2-tuple.  If not specified, or if set to None, the
image will be saved without tiling.</dd>
<dt><strong>quality_mode</strong></dt>
<dd>Either <cite>&#8220;rates&#8221;</cite> or <cite>&#8220;dB&#8221;</cite> depending on the units you want to use to
specify image quality.</dd>
<dt><strong>quality_layers</strong></dt>
<dd>A sequence of numbers, each of which represents either an approximate size
reduction (if quality mode is <cite>&#8220;rates&#8221;</cite>) or a signal to noise ratio value
in decibels.  If not specified, defaults to a single layer of full quality.</dd>
<dt><strong>num_resolutions</strong></dt>
<dd>The number of different image resolutions to be stored (which corresponds
to the number of Discrete Wavelet Transform decompositions plus one).</dd>
<dt><strong>codeblock_size</strong></dt>
<dd>The code-block size as a 2-tuple.  Minimum size is 4 x 4, maximum is 1024 x
1024, with the additional restriction that no code-block may have more
than 4096 coefficients (i.e. the product of the two numbers must be no
greater than 4096).</dd>
<dt><strong>precinct_size</strong></dt>
<dd>The precinct size as a 2-tuple.  Must be a power of two along both axes,
and must be greater than the code-block size.</dd>
<dt><strong>irreversible</strong></dt>
<dd>If <tt class="docutils literal"><span class="pre">True</span></tt>, use the lossy Irreversible Color Transformation
followed by DWT 9-7.  Defaults to <tt class="docutils literal"><span class="pre">False</span></tt>, which means to use the
Reversible Color Transformation with DWT 5-3.</dd>
<dt><strong>progression</strong></dt>
<dd>Controls the progression order; must be one of <tt class="docutils literal"><span class="pre">&quot;LRCP&quot;</span></tt>, <tt class="docutils literal"><span class="pre">&quot;RLCP&quot;</span></tt>,
<tt class="docutils literal"><span class="pre">&quot;RPCL&quot;</span></tt>, <tt class="docutils literal"><span class="pre">&quot;PCRL&quot;</span></tt>, <tt class="docutils literal"><span class="pre">&quot;CPRL&quot;</span></tt>.  The letters stand for Component,
Position, Resolution and Layer respectively and control the order of
encoding, the idea being that e.g. an image encoded using LRCP mode can
have its quality layers decoded as they arrive at the decoder, while one
encoded using RLCP mode will have increasing resolutions decoded as they
arrive, and so on.</dd>
<dt><strong>cinema_mode</strong></dt>
<dd>Set the encoder to produce output compliant with the digital cinema
specifications.  The options here are <tt class="docutils literal"><span class="pre">&quot;no&quot;</span></tt> (the default),
<tt class="docutils literal"><span class="pre">&quot;cinema2k-24&quot;</span></tt> for 24fps 2K, <tt class="docutils literal"><span class="pre">&quot;cinema2k-48&quot;</span></tt> for 48fps 2K, and
<tt class="docutils literal"><span class="pre">&quot;cinema4k-24&quot;</span></tt> for 24fps 4K.  Note that for compliant 2K files,
<em>at least one</em> of your image dimensions must match 2048 x 1080, while
for compliant 4K files, <em>at least one</em> of the dimensions must match
4096 x 2160.</dd>
</dl>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>To enable JPEG 2000 support, you need to build and install the OpenJPEG
library, version 2.0.0 or higher, before building the Python Imaging
Library.</p>
<p class="last">Windows users can install the OpenJPEG binaries available on the
OpenJPEG website, but must add them to their PATH in order to use PIL (if
you fail to do this, you will get errors about not being able to load the
<tt class="docutils literal"><span class="pre">_imaging</span></tt> DLL).</p>
</div>
</div>
<div class="section" id="msp">
<h3>MSP<a class="headerlink" href="#msp" title="Permalink to this headline">¶</a></h3>
<p>PIL identifies and reads MSP files from Windows 1 and 2. The library writes
uncompressed (Windows 1) versions of this format.</p>
</div>
<div class="section" id="pcx">
<h3>PCX<a class="headerlink" href="#pcx" title="Permalink to this headline">¶</a></h3>
<p>PIL reads and writes PCX files containing <tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">L</span></tt>, <tt class="docutils literal"><span class="pre">P</span></tt>, or <tt class="docutils literal"><span class="pre">RGB</span></tt> data.</p>
</div>
<div class="section" id="png">
<h3>PNG<a class="headerlink" href="#png" title="Permalink to this headline">¶</a></h3>
<p>PIL identifies, reads, and writes PNG files containing <tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">L</span></tt>, <tt class="docutils literal"><span class="pre">P</span></tt>,
<tt class="docutils literal"><span class="pre">RGB</span></tt>, or <tt class="docutils literal"><span class="pre">RGBA</span></tt> data. Interlaced files are supported as of v1.1.7.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> properties, when appropriate:</p>
<dl class="docutils">
<dt><strong>gamma</strong></dt>
<dd>Gamma, given as a floating point number.</dd>
<dt><strong>transparency</strong></dt>
<dd>Transparency color index. This key is omitted if the image is not a
transparent palette image.</dd>
</dl>
<p><tt class="docutils literal"><span class="pre">Open</span></tt> also sets <tt class="docutils literal"><span class="pre">Image.text</span></tt> to a list of the values of the
<tt class="docutils literal"><span class="pre">tEXt</span></tt>, <tt class="docutils literal"><span class="pre">zTXt</span></tt>, and <tt class="docutils literal"><span class="pre">iTXt</span></tt> chunks of the PNG image. Individual
compressed chunks are limited to a decompressed size of
<tt class="docutils literal"><span class="pre">PngImagePlugin.MAX_TEXT_CHUNK</span></tt>, by default 1MB, to prevent
decompression bombs. Additionally, the total size of all of the text
chunks is limited to <tt class="docutils literal"><span class="pre">PngImagePlugin.MAX_TEXT_MEMORY</span></tt>, defaulting to
64MB.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">save()</span></tt> method supports the following options:</p>
<dl class="docutils">
<dt><strong>optimize</strong></dt>
<dd>If present, instructs the PNG writer to make the output file as small as
possible. This includes extra processing in order to find optimal encoder
settings.</dd>
<dt><strong>transparency</strong></dt>
<dd>For <tt class="docutils literal"><span class="pre">P</span></tt>, <tt class="docutils literal"><span class="pre">L</span></tt>, and <tt class="docutils literal"><span class="pre">RGB</span></tt> images, this option controls what
color image to mark as transparent.</dd>
<dt><strong>bits (experimental)</strong></dt>
<dd>For <tt class="docutils literal"><span class="pre">P</span></tt> images, this option controls how many bits to store. If omitted,
the PNG writer uses 8 bits (256 colors).</dd>
<dt><strong>dictionary (experimental)</strong></dt>
<dd>Set the ZLIB encoder dictionary.</dd>
</dl>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">To enable PNG support, you need to build and install the ZLIB compression
library before building the Python Imaging Library. See the distribution
README for details.</p>
</div>
</div>
<div class="section" id="ppm">
<h3>PPM<a class="headerlink" href="#ppm" title="Permalink to this headline">¶</a></h3>
<p>PIL reads and writes PBM, PGM and PPM files containing <tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">L</span></tt> or <tt class="docutils literal"><span class="pre">RGB</span></tt>
data.</p>
</div>
<div class="section" id="spider">
<h3>SPIDER<a class="headerlink" href="#spider" title="Permalink to this headline">¶</a></h3>
<p>PIL reads and writes SPIDER image files of 32-bit floating point data
(&#8220;F;32F&#8221;).</p>
<p>PIL also reads SPIDER stack files containing sequences of SPIDER images. The
<a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.seek" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">seek()</span></tt></a> and <a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.tell" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">tell()</span></tt></a> methods are supported, and
random access is allowed.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following attributes:</p>
<dl class="docutils">
<dt><strong>format</strong></dt>
<dd>Set to <tt class="docutils literal"><span class="pre">SPIDER</span></tt></dd>
<dt><strong>istack</strong></dt>
<dd>Set to 1 if the file is an image stack, else 0.</dd>
<dt><strong>nimages</strong></dt>
<dd>Set to the number of images in the stack.</dd>
</dl>
<p>A convenience method, <tt class="xref py py-meth docutils literal"><span class="pre">convert2byte()</span></tt>, is provided for
converting floating point data to byte data (mode <tt class="docutils literal"><span class="pre">L</span></tt>):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">im</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s">&#39;image001.spi&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">convert2byte</span><span class="p">()</span>
</pre></div>
</div>
<div class="section" id="writing-files-in-spider-format">
<h4>Writing files in SPIDER format<a class="headerlink" href="#writing-files-in-spider-format" title="Permalink to this headline">¶</a></h4>
<p>The extension of SPIDER files may be any 3 alphanumeric characters. Therefore
the output format must be specified explicitly:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">im</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s">&#39;newimage.spi&#39;</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">&#39;SPIDER&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>For more information about the SPIDER image processing package, see the
<a class="reference external" href="http://www.wadsworth.org/spider_doc/spider/docs/master.html">SPIDER home page</a> at <a class="reference external" href="http://www.wadsworth.org/">Wadsworth Center</a>.</p>
</div>
</div>
<div class="section" id="tiff">
<h3>TIFF<a class="headerlink" href="#tiff" title="Permalink to this headline">¶</a></h3>
<p>PIL reads and writes TIFF files. It can read both striped and tiled images,
pixel and plane interleaved multi-band images, and either uncompressed, or
Packbits, LZW, or JPEG compressed images.</p>
<p>If you have libtiff and its headers installed, PIL can read and write many more
kinds of compressed TIFF files. If not, PIL will always write uncompressed
files.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> properties:</p>
<dl class="docutils">
<dt><strong>compression</strong></dt>
<dd>Compression mode.</dd>
<dt><strong>dpi</strong></dt>
<dd><p class="first">Image resolution as an (xdpi, ydpi) tuple, where applicable. You can use
the <tt class="xref py py-attr docutils literal"><span class="pre">tag</span></tt> attribute to get more detailed
information about the image resolution.</p>
<div class="last versionadded">
<p><span class="versionmodified">New in version 1.1.5.</span></p>
</div>
</dd>
</dl>
<p>In addition, the <tt class="xref py py-attr docutils literal"><span class="pre">tag</span></tt> attribute contains a
dictionary of decoded TIFF fields. Values are stored as either strings or
tuples. Note that only short, long and ASCII tags are correctly unpacked by
this release.</p>
<div class="section" id="saving-tiff-images">
<h4>Saving Tiff Images<a class="headerlink" href="#saving-tiff-images" title="Permalink to this headline">¶</a></h4>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">save()</span></tt> method can take the following keyword arguments:</p>
<dl class="docutils">
<dt><strong>tiffinfo</strong></dt>
<dd><p class="first">A <tt class="xref py py-class docutils literal"><span class="pre">ImageFileDirectory</span></tt> object or dict
object containing tiff tags and values. The TIFF field type is
autodetected for Numeric and string values, any other types
require using an <tt class="xref py py-class docutils literal"><span class="pre">ImageFileDirectory</span></tt>
object and setting the type in
<tt class="xref py py-attr docutils literal"><span class="pre">tagtype</span></tt> with
the appropriate numerical value from
<tt class="docutils literal"><span class="pre">TiffTags.TYPES</span></tt>.</p>
<div class="last versionadded">
<p><span class="versionmodified">New in version 2.3.0.</span></p>
</div>
</dd>
<dt><strong>compression</strong></dt>
<dd><dl class="first last docutils">
<dt>A string containing the desired compression method for the</dt>
<dd>file. (valid only with libtiff installed) Valid compression
methods are: <tt class="docutils literal"><span class="pre">[None,</span> <span class="pre">&quot;tiff_ccitt&quot;,</span> <span class="pre">&quot;group3&quot;,</span> <span class="pre">&quot;group4&quot;,</span>
<span class="pre">&quot;tiff_jpeg&quot;,</span> <span class="pre">&quot;tiff_adobe_deflate&quot;,</span> <span class="pre">&quot;tiff_thunderscan&quot;,</span>
<span class="pre">&quot;tiff_deflate&quot;,</span> <span class="pre">&quot;tiff_sgilog&quot;,</span> <span class="pre">&quot;tiff_sgilog24&quot;,</span> <span class="pre">&quot;tiff_raw_16&quot;]</span></tt></dd>
</dl>
</dd>
</dl>
<p>These arguments to set the tiff header fields are an alternative to using the general tags available through tiffinfo.</p>
<p><strong>description</strong></p>
<p><strong>software</strong></p>
<p><strong>date time</strong></p>
<p><strong>artist</strong></p>
<dl class="docutils">
<dt><strong>copyright</strong></dt>
<dd>Strings</dd>
<dt><strong>resolution unit</strong></dt>
<dd>A string of &#8220;inch&#8221;, &#8220;centimeter&#8221; or &#8220;cm&#8221;</dd>
</dl>
<p><strong>resolution</strong></p>
<p><strong>x resolution</strong></p>
<p><strong>y resolution</strong></p>
<dl class="docutils">
<dt><strong>dpi</strong></dt>
<dd>Either a Float, Integer, or 2 tuple of (numerator,
denominator). Resolution implies an equal x and y resolution, dpi
also implies a unit of inches.</dd>
</dl>
</div>
</div>
<div class="section" id="webp">
<h3>WebP<a class="headerlink" href="#webp" title="Permalink to this headline">¶</a></h3>
<p>PIL reads and writes WebP files. The specifics of PIL&#8217;s capabilities with this
format are currently undocumented.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">save()</span></tt> method supports the following options:</p>
<dl class="docutils">
<dt><strong>lossless</strong></dt>
<dd>If present, instructs the WEBP writer to use lossless
compression.</dd>
<dt><strong>quality</strong></dt>
<dd>Integer, 1-100, Defaults to 80. Sets the quality level for
lossy compression.</dd>
<dt><strong>icc_procfile</strong></dt>
<dd>The ICC Profile to include in the saved file. Only supported if
the system webp library was built with webpmux support.</dd>
<dt><strong>exif</strong></dt>
<dd>The exif data to include in the saved file. Only supported if
the system webp library was built with webpmux support.</dd>
</dl>
</div>
<div class="section" id="xbm">
<h3>XBM<a class="headerlink" href="#xbm" title="Permalink to this headline">¶</a></h3>
<p>PIL reads and writes X bitmap files (mode <tt class="docutils literal"><span class="pre">1</span></tt>).</p>
</div>
<div class="section" id="xv-thumbnails">
<h3>XV Thumbnails<a class="headerlink" href="#xv-thumbnails" title="Permalink to this headline">¶</a></h3>
<p>PIL can read XV thumbnail files.</p>
</div>
</div>
<div class="section" id="read-only-formats">
<h2>Read-only formats<a class="headerlink" href="#read-only-formats" title="Permalink to this headline">¶</a></h2>
<div class="section" id="cur">
<h3>CUR<a class="headerlink" href="#cur" title="Permalink to this headline">¶</a></h3>
<p>CUR is used to store cursors on Windows. The CUR decoder reads the largest
available cursor. Animated cursors are not supported.</p>
</div>
<div class="section" id="dcx">
<h3>DCX<a class="headerlink" href="#dcx" title="Permalink to this headline">¶</a></h3>
<p>DCX is a container file format for PCX files, defined by Intel. The DCX format
is commonly used in fax applications. The DCX decoder can read files containing
<tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">L</span></tt>, <tt class="docutils literal"><span class="pre">P</span></tt>, or <tt class="docutils literal"><span class="pre">RGB</span></tt> data.</p>
<p>When the file is opened, only the first image is read. You can use
<a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.seek" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">seek()</span></tt></a> or <a class="reference internal" href="../reference/ImageSequence.html#module-PIL.ImageSequence" title="PIL.ImageSequence"><tt class="xref py py-mod docutils literal"><span class="pre">ImageSequence</span></tt></a> to read other images.</p>
</div>
<div class="section" id="fli-flc">
<h3>FLI, FLC<a class="headerlink" href="#fli-flc" title="Permalink to this headline">¶</a></h3>
<p>PIL reads Autodesk FLI and FLC animations.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> properties:</p>
<dl class="docutils">
<dt><strong>duration</strong></dt>
<dd>The delay (in milliseconds) between each frame.</dd>
</dl>
</div>
<div class="section" id="fpx">
<h3>FPX<a class="headerlink" href="#fpx" title="Permalink to this headline">¶</a></h3>
<p>PIL reads Kodak FlashPix files. In the current version, only the highest
resolution image is read from the file, and the viewing transform is not taken
into account.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">To enable full FlashPix support, you need to build and install the IJG JPEG
library before building the Python Imaging Library. See the distribution
README for details.</p>
</div>
</div>
<div class="section" id="gbr">
<h3>GBR<a class="headerlink" href="#gbr" title="Permalink to this headline">¶</a></h3>
<p>The GBR decoder reads GIMP brush files.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> properties:</p>
<dl class="docutils">
<dt><strong>description</strong></dt>
<dd>The brush name.</dd>
</dl>
</div>
<div class="section" id="gd">
<h3>GD<a class="headerlink" href="#gd" title="Permalink to this headline">¶</a></h3>
<p>PIL reads uncompressed GD files. Note that this file format cannot be
automatically identified, so you must use <tt class="xref py py-func docutils literal"><span class="pre">PIL.GdImageFile.open()</span></tt> to
read such a file.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> properties:</p>
<dl class="docutils">
<dt><strong>transparency</strong></dt>
<dd>Transparency color index. This key is omitted if the image is not
transparent.</dd>
</dl>
</div>
<div class="section" id="ico">
<h3>ICO<a class="headerlink" href="#ico" title="Permalink to this headline">¶</a></h3>
<p>ICO is used to store icons on Windows. The largest available icon is read.</p>
</div>
<div class="section" id="icns">
<h3>ICNS<a class="headerlink" href="#icns" title="Permalink to this headline">¶</a></h3>
<p>PIL reads Mac OS X <tt class="docutils literal"><span class="pre">.icns</span></tt> files.  By default, the largest available icon is
read, though you can override this by setting the <tt class="xref py py-attr docutils literal"><span class="pre">size</span></tt>
property before calling <tt class="xref py py-meth docutils literal"><span class="pre">load()</span></tt>.  The
<tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> property:</p>
<dl class="docutils">
<dt><strong>sizes</strong></dt>
<dd>A list of supported sizes found in this icon file; these are a
3-tuple, <tt class="docutils literal"><span class="pre">(width,</span> <span class="pre">height,</span> <span class="pre">scale)</span></tt>, where <tt class="docutils literal"><span class="pre">scale</span></tt> is 2 for a retina
icon and 1 for a standard icon.  You <em>are</em> permitted to use this 3-tuple
format for the <tt class="xref py py-attr docutils literal"><span class="pre">size</span></tt> property if you set it
before calling <tt class="xref py py-meth docutils literal"><span class="pre">load()</span></tt>; after loading, the size
will be reset to a 2-tuple containing pixel dimensions (so, e.g. if you
ask for <tt class="docutils literal"><span class="pre">(512,</span> <span class="pre">512,</span> <span class="pre">2)</span></tt>, the final value of
<tt class="xref py py-attr docutils literal"><span class="pre">size</span></tt> will be <tt class="docutils literal"><span class="pre">(1024,</span> <span class="pre">1024)</span></tt>).</dd>
</dl>
</div>
<div class="section" id="imt">
<h3>IMT<a class="headerlink" href="#imt" title="Permalink to this headline">¶</a></h3>
<p>PIL reads Image Tools images containing <tt class="docutils literal"><span class="pre">L</span></tt> data.</p>
</div>
<div class="section" id="iptc-naa">
<h3>IPTC/NAA<a class="headerlink" href="#iptc-naa" title="Permalink to this headline">¶</a></h3>
<p>PIL provides limited read support for IPTC/NAA newsphoto files.</p>
</div>
<div class="section" id="mcidas">
<h3>MCIDAS<a class="headerlink" href="#mcidas" title="Permalink to this headline">¶</a></h3>
<p>PIL identifies and reads 8-bit McIdas area files.</p>
<p>MIC (read only)</p>
<p>PIL identifies and reads Microsoft Image Composer (MIC) files. When opened, the
first sprite in the file is loaded. You can use <a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.seek" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">seek()</span></tt></a> and
<a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.tell" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">tell()</span></tt></a> to read other sprites from the file.</p>
</div>
<div class="section" id="mpo">
<h3>MPO<a class="headerlink" href="#mpo" title="Permalink to this headline">¶</a></h3>
<p>Pillow identifies and reads Multi Picture Object (MPO) files, loading the primary
image when first opened. The <a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.seek" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">seek()</span></tt></a> and <a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.tell" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">tell()</span></tt></a>
methods may be used to read other pictures from the file. The pictures are
zero-indexed and random access is supported.</p>
<p>MIC (read only)</p>
<p>Pillow identifies and reads Microsoft Image Composer (MIC) files. When opened, the
first sprite in the file is loaded. You can use <a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.seek" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">seek()</span></tt></a> and
<a class="reference external" href="http://docs.python.org/2/library/stdtypes.html#file.tell" title="(in Python v2.7)"><tt class="xref py py-meth docutils literal"><span class="pre">tell()</span></tt></a> to read other sprites from the file.</p>
</div>
<div class="section" id="pcd">
<h3>PCD<a class="headerlink" href="#pcd" title="Permalink to this headline">¶</a></h3>
<p>PIL reads PhotoCD files containing <tt class="docutils literal"><span class="pre">RGB</span></tt> data. By default, the 768x512
resolution is read. You can use the <tt class="xref py py-meth docutils literal"><span class="pre">draft()</span></tt> method to
read the lower resolution versions instead, thus effectively resizing the image
to 384x256 or 192x128. Higher resolutions cannot be read by the Python Imaging
Library.</p>
</div>
<div class="section" id="psd">
<h3>PSD<a class="headerlink" href="#psd" title="Permalink to this headline">¶</a></h3>
<p>PIL identifies and reads PSD files written by Adobe Photoshop 2.5 and 3.0.</p>
</div>
<div class="section" id="sgi">
<h3>SGI<a class="headerlink" href="#sgi" title="Permalink to this headline">¶</a></h3>
<p>PIL reads uncompressed <tt class="docutils literal"><span class="pre">L</span></tt>, <tt class="docutils literal"><span class="pre">RGB</span></tt>, and <tt class="docutils literal"><span class="pre">RGBA</span></tt> files.</p>
</div>
<div class="section" id="tga">
<h3>TGA<a class="headerlink" href="#tga" title="Permalink to this headline">¶</a></h3>
<p>PIL reads 24- and 32-bit uncompressed and run-length encoded TGA files.</p>
</div>
<div class="section" id="wal">
<h3>WAL<a class="headerlink" href="#wal" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.4.</span></p>
</div>
<p>PIL reads Quake2 WAL texture files.</p>
<p>Note that this file format cannot be automatically identified, so you must use
the open function in the <tt class="xref py py-mod docutils literal"><span class="pre">WalImageFile</span></tt> module to read files in
this format.</p>
<p>By default, a Quake2 standard palette is attached to the texture. To override
the palette, use the putpalette method.</p>
</div>
<div class="section" id="xpm">
<h3>XPM<a class="headerlink" href="#xpm" title="Permalink to this headline">¶</a></h3>
<p>PIL reads X pixmap files (mode <tt class="docutils literal"><span class="pre">P</span></tt>) with 256 colors or less.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">open()</span></tt> method sets the following
<tt class="xref py py-attr docutils literal"><span class="pre">info</span></tt> properties:</p>
<dl class="docutils">
<dt><strong>transparency</strong></dt>
<dd>Transparency color index. This key is omitted if the image is not
transparent.</dd>
</dl>
</div>
</div>
<div class="section" id="write-only-formats">
<h2>Write-only formats<a class="headerlink" href="#write-only-formats" title="Permalink to this headline">¶</a></h2>
<div class="section" id="palm">
<h3>PALM<a class="headerlink" href="#palm" title="Permalink to this headline">¶</a></h3>
<p>PIL provides write-only support for PALM pixmap files.</p>
<p>The format code is <tt class="docutils literal"><span class="pre">Palm</span></tt>, the extension is <tt class="docutils literal"><span class="pre">.palm</span></tt>.</p>
</div>
<div class="section" id="pdf">
<h3>PDF<a class="headerlink" href="#pdf" title="Permalink to this headline">¶</a></h3>
<p>PIL can write PDF (Acrobat) images. Such images are written as binary PDF 1.1
files, using either JPEG or HEX encoding depending on the image mode (and
whether JPEG support is available or not).</p>
</div>
<div class="section" id="pixar-read-only">
<h3>PIXAR (read only)<a class="headerlink" href="#pixar-read-only" title="Permalink to this headline">¶</a></h3>
<p>PIL provides limited support for PIXAR raster files. The library can identify
and read “dumped” RGB files.</p>
<p>The format code is <tt class="docutils literal"><span class="pre">PIXAR</span></tt>.</p>
</div>
</div>
<div class="section" id="identify-only-formats">
<h2>Identify-only formats<a class="headerlink" href="#identify-only-formats" title="Permalink to this headline">¶</a></h2>
<div class="section" id="bufr">
<h3>BUFR<a class="headerlink" href="#bufr" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.3.</span></p>
</div>
<p>PIL provides a stub driver for BUFR files.</p>
<p>To add read or write support to your application, use
<tt class="xref py py-func docutils literal"><span class="pre">PIL.BufrStubImagePlugin.register_handler()</span></tt>.</p>
</div>
<div class="section" id="fits">
<h3>FITS<a class="headerlink" href="#fits" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.5.</span></p>
</div>
<p>PIL provides a stub driver for FITS files.</p>
<p>To add read or write support to your application, use
<tt class="xref py py-func docutils literal"><span class="pre">PIL.FitsStubImagePlugin.register_handler()</span></tt>.</p>
</div>
<div class="section" id="grib">
<h3>GRIB<a class="headerlink" href="#grib" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.5.</span></p>
</div>
<p>PIL provides a stub driver for GRIB files.</p>
<p>The driver requires the file to start with a GRIB header. If you have files
with embedded GRIB data, or files with multiple GRIB fields, your application
has to seek to the header before passing the file handle to PIL.</p>
<p>To add read or write support to your application, use
<tt class="xref py py-func docutils literal"><span class="pre">PIL.GribStubImagePlugin.register_handler()</span></tt>.</p>
</div>
<div class="section" id="hdf5">
<h3>HDF5<a class="headerlink" href="#hdf5" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.5.</span></p>
</div>
<p>PIL provides a stub driver for HDF5 files.</p>
<p>To add read or write support to your application, use
<tt class="xref py py-func docutils literal"><span class="pre">PIL.Hdf5StubImagePlugin.register_handler()</span></tt>.</p>
</div>
<div class="section" id="mpeg">
<h3>MPEG<a class="headerlink" href="#mpeg" title="Permalink to this headline">¶</a></h3>
<p>PIL identifies MPEG files.</p>
</div>
<div class="section" id="wmf">
<h3>WMF<a class="headerlink" href="#wmf" title="Permalink to this headline">¶</a></h3>
<p>PIL can identify placable WMF files.</p>
<p>In PIL 1.1.4 and earlier, the WMF driver provides some limited rendering
support, but not enough to be useful for any real application.</p>
<p>In PIL 1.1.5 and later, the WMF driver is a stub driver. To add WMF read or
write support to your application, use
<tt class="xref py py-func docutils literal"><span class="pre">PIL.WmfImagePlugin.register_handler()</span></tt> to register a WMF handler.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">PIL</span> <span class="kn">import</span> <span class="n">Image</span>
<span class="kn">from</span> <span class="nn">PIL</span> <span class="kn">import</span> <span class="n">WmfImagePlugin</span>

<span class="k">class</span> <span class="nc">WmfHandler</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">im</span><span class="p">):</span>
        <span class="o">...</span>
    <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">im</span><span class="p">):</span>
        <span class="o">...</span>
        <span class="k">return</span> <span class="n">image</span>
    <span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">im</span><span class="p">,</span> <span class="n">fp</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="o">...</span>

<span class="n">wmf_handler</span> <span class="o">=</span> <span class="n">WmfHandler</span><span class="p">()</span>

<span class="n">WmfImagePlugin</span><span class="o">.</span><span class="n">register_handler</span><span class="p">(</span><span class="n">wmf_handler</span><span class="p">)</span>

<span class="n">im</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s">&quot;sample.wmf&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Image file formats</a><ul>
<li><a class="reference internal" href="#fully-supported-formats">Fully supported formats</a><ul>
<li><a class="reference internal" href="#bmp">BMP</a></li>
<li><a class="reference internal" href="#eps">EPS</a></li>
<li><a class="reference internal" href="#gif">GIF</a><ul>
<li><a class="reference internal" href="#reading-sequences">Reading sequences</a></li>
<li><a class="reference internal" href="#reading-local-images">Reading local images</a></li>
</ul>
</li>
<li><a class="reference internal" href="#im">IM</a></li>
<li><a class="reference internal" href="#jpeg">JPEG</a></li>
<li><a class="reference internal" href="#jpeg-2000">JPEG 2000</a></li>
<li><a class="reference internal" href="#msp">MSP</a></li>
<li><a class="reference internal" href="#pcx">PCX</a></li>
<li><a class="reference internal" href="#png">PNG</a></li>
<li><a class="reference internal" href="#ppm">PPM</a></li>
<li><a class="reference internal" href="#spider">SPIDER</a><ul>
<li><a class="reference internal" href="#writing-files-in-spider-format">Writing files in SPIDER format</a></li>
</ul>
</li>
<li><a class="reference internal" href="#tiff">TIFF</a><ul>
<li><a class="reference internal" href="#saving-tiff-images">Saving Tiff Images</a></li>
</ul>
</li>
<li><a class="reference internal" href="#webp">WebP</a></li>
<li><a class="reference internal" href="#xbm">XBM</a></li>
<li><a class="reference internal" href="#xv-thumbnails">XV Thumbnails</a></li>
</ul>
</li>
<li><a class="reference internal" href="#read-only-formats">Read-only formats</a><ul>
<li><a class="reference internal" href="#cur">CUR</a></li>
<li><a class="reference internal" href="#dcx">DCX</a></li>
<li><a class="reference internal" href="#fli-flc">FLI, FLC</a></li>
<li><a class="reference internal" href="#fpx">FPX</a></li>
<li><a class="reference internal" href="#gbr">GBR</a></li>
<li><a class="reference internal" href="#gd">GD</a></li>
<li><a class="reference internal" href="#ico">ICO</a></li>
<li><a class="reference internal" href="#icns">ICNS</a></li>
<li><a class="reference internal" href="#imt">IMT</a></li>
<li><a class="reference internal" href="#iptc-naa">IPTC/NAA</a></li>
<li><a class="reference internal" href="#mcidas">MCIDAS</a></li>
<li><a class="reference internal" href="#mpo">MPO</a></li>
<li><a class="reference internal" href="#pcd">PCD</a></li>
<li><a class="reference internal" href="#psd">PSD</a></li>
<li><a class="reference internal" href="#sgi">SGI</a></li>
<li><a class="reference internal" href="#tga">TGA</a></li>
<li><a class="reference internal" href="#wal">WAL</a></li>
<li><a class="reference internal" href="#xpm">XPM</a></li>
</ul>
</li>
<li><a class="reference internal" href="#write-only-formats">Write-only formats</a><ul>
<li><a class="reference internal" href="#palm">PALM</a></li>
<li><a class="reference internal" href="#pdf">PDF</a></li>
<li><a class="reference internal" href="#pixar-read-only">PIXAR (read only)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#identify-only-formats">Identify-only formats</a><ul>
<li><a class="reference internal" href="#bufr">BUFR</a></li>
<li><a class="reference internal" href="#fits">FITS</a></li>
<li><a class="reference internal" href="#grib">GRIB</a></li>
<li><a class="reference internal" href="#hdf5">HDF5</a></li>
<li><a class="reference internal" href="#mpeg">MPEG</a></li>
<li><a class="reference internal" href="#wmf">WMF</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/handbook/image-file-formats.txt"
           rel="nofollow">Show Source</a></li>
  </ul><h3>Need help?</h3>
<p>
    You can get help via IRC at <a href="irc://irc.freenode.net#pil">irc://irc.freenode.net#pil</a> or Stack Overflow <a href="http://stackoverflow.com/questions/tagged/pillow">here</a> and <a href="http://stackoverflow.com/questions/tagged/pil">here</a>. Please <a href="https://github.com/python-pillow/Pillow/issues/new">report issues on GitHub</a>.
</p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <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="writing-your-own-file-decoder.html" title="Writing your own file decoder"
             >next</a> |</li>
        <li class="right" >
          <a href="appendices.html" title="Appendices"
             >previous</a> |</li>
        <li><a href="../index.html">Home</a> &raquo;</li>
          <li><a href="appendices.html" >Appendices</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 1997-2011 by Secret Labs AB, 1995-2011 by Fredrik Lundh, 2010-2013 Alex Clark.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
    </div>
  </body>
</html>