<!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>ImageSequence Module — 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="Reference" href="index.html" /> <link rel="next" title="ImageStat Module" href="ImageStat.html" /> <link rel="prev" title="ImageQt Module" href="ImageQt.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="ImageStat.html" title="ImageStat Module" accesskey="N">next</a> |</li> <li class="right" > <a href="ImageQt.html" title="ImageQt Module" accesskey="P">previous</a> |</li> <li><a href="../index.html">Home</a> »</li> <li><a href="index.html" accesskey="U">Reference</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <span class="target" id="module-PIL.ImageSequence"></span><div class="section" id="imagesequence-module"> <h1><tt class="xref py py-mod docutils literal"><span class="pre">ImageSequence</span></tt> Module<a class="headerlink" href="#imagesequence-module" title="Permalink to this headline">¶</a></h1> <p>The <tt class="xref py py-mod docutils literal"><span class="pre">ImageSequence</span></tt> module contains a wrapper class that lets you iterate over the frames of an image sequence.</p> <div class="section" id="extracting-frames-from-an-animation"> <h2>Extracting frames from an animation<a class="headerlink" href="#extracting-frames-from-an-animation" title="Permalink to this headline">¶</a></h2> <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="p">,</span> <span class="n">ImageSequence</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">"animation.fli"</span><span class="p">)</span> <span class="n">index</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">for</span> <span class="n">frame</span> <span class="ow">in</span> <span class="n">ImageSequence</span><span class="o">.</span><span class="n">Iterator</span><span class="p">(</span><span class="n">im</span><span class="p">):</span> <span class="n">frame</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s">"frame</span><span class="si">%d</span><span class="s">.png"</span> <span class="o">%</span> <span class="n">index</span><span class="p">)</span> <span class="n">index</span> <span class="o">=</span> <span class="n">index</span> <span class="o">+</span> <span class="mi">1</span> </pre></div> </div> </div> <div class="section" id="the-iterator-class"> <h2>The <a class="reference internal" href="#PIL.ImageSequence.Iterator" title="PIL.ImageSequence.Iterator"><tt class="xref py py-class docutils literal"><span class="pre">Iterator</span></tt></a> class<a class="headerlink" href="#the-iterator-class" title="Permalink to this headline">¶</a></h2> <dl class="class"> <dt id="PIL.ImageSequence.Iterator"> <em class="property">class </em><tt class="descclassname">PIL.ImageSequence.</tt><tt class="descname">Iterator</tt><big>(</big><em>im</em><big>)</big><a class="reference internal" href="../_modules/PIL/ImageSequence.html#Iterator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#PIL.ImageSequence.Iterator" title="Permalink to this definition">¶</a></dt> <dd><p>This class implements an iterator object that can be used to loop over an image sequence.</p> <p>You can use the <tt class="docutils literal"><span class="pre">[]</span></tt> operator to access elements by index. This operator will raise an <tt class="xref py py-exc docutils literal"><span class="pre">IndexError</span></tt> if you try to access a nonexistent frame.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>im</strong> – An image object.</td> </tr> </tbody> </table> </dd></dl> </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="#"><tt class="docutils literal"><span class="pre">ImageSequence</span></tt> Module</a><ul> <li><a class="reference internal" href="#extracting-frames-from-an-animation">Extracting frames from an animation</a></li> <li><a class="reference internal" href="#the-iterator-class">The <tt class="docutils literal"><span class="pre">Iterator</span></tt> class</a></li> </ul> </li> </ul> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/reference/ImageSequence.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="ImageStat.html" title="ImageStat Module" >next</a> |</li> <li class="right" > <a href="ImageQt.html" title="ImageQt Module" >previous</a> |</li> <li><a href="../index.html">Home</a> »</li> <li><a href="index.html" >Reference</a> »</li> </ul> </div> <div class="footer"> © 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>