Sophie

Sophie

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

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>ImageDraw Module &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="Reference" href="index.html" />
    <link rel="next" title="ImageEnhance Module" href="ImageEnhance.html" />
    <link rel="prev" title="ImageCms Module" href="ImageCms.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="ImageEnhance.html" title="ImageEnhance Module"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="ImageCms.html" title="ImageCms Module"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">Home</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">Reference</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <span class="target" id="module-PIL.ImageDraw"></span><div class="section" id="imagedraw-module">
<h1><tt class="xref py py-mod docutils literal"><span class="pre">ImageDraw</span></tt> Module<a class="headerlink" href="#imagedraw-module" title="Permalink to this headline">¶</a></h1>
<p>The <tt class="xref py py-mod docutils literal"><span class="pre">ImageDraw</span></tt> module provide simple 2D graphics for
<tt class="xref py py-class docutils literal"><span class="pre">Image</span></tt> objects.  You can use this module to create new
images, annotate or retouch existing images, and to generate graphics on the
fly for web use.</p>
<p>For a more advanced drawing library for PIL, see the <a class="reference external" href="http://effbot.org/zone/aggdraw-index.htm">aggdraw module</a>.</p>
<div class="section" id="example-draw-a-gray-cross-over-an-image">
<h2>Example: Draw a gray cross over an image<a class="headerlink" href="#example-draw-a-gray-cross-over-an-image" 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">ImageDraw</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;lena.pgm&quot;</span><span class="p">)</span>

<span class="n">draw</span> <span class="o">=</span> <span class="n">ImageDraw</span><span class="o">.</span><span class="n">Draw</span><span class="p">(</span><span class="n">im</span><span class="p">)</span>
<span class="n">draw</span><span class="o">.</span><span class="n">line</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">fill</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span>
<span class="n">draw</span><span class="o">.</span><span class="n">line</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="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">im</span><span class="o">.</span><span class="n">size</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="n">fill</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span>
<span class="k">del</span> <span class="n">draw</span>

<span class="c"># write to stdout</span>
<span class="n">im</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span> <span class="s">&quot;PNG&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="concepts">
<h2>Concepts<a class="headerlink" href="#concepts" title="Permalink to this headline">¶</a></h2>
<div class="section" id="coordinates">
<h3>Coordinates<a class="headerlink" href="#coordinates" title="Permalink to this headline">¶</a></h3>
<p>The graphics interface uses the same coordinate system as PIL itself, with (0,
0) in the upper left corner.</p>
</div>
<div class="section" id="colors">
<h3>Colors<a class="headerlink" href="#colors" title="Permalink to this headline">¶</a></h3>
<p>To specify colors, you can use numbers or tuples just as you would use with
<tt class="xref py py-meth docutils literal"><span class="pre">PIL.Image.Image.new()</span></tt> or <tt class="xref py py-meth docutils literal"><span class="pre">PIL.Image.Image.putpixel()</span></tt>. For “1”,
“L”, and “I” images, use integers. For “RGB” images, use a 3-tuple containing
integer values. For “F” images, use integer or floating point values.</p>
<p>For palette images (mode “P”), use integers as color indexes. In 1.1.4 and
later, you can also use RGB 3-tuples or color names (see below). The drawing
layer will automatically assign color indexes, as long as you don’t draw with
more than 256 colors.</p>
</div>
<div class="section" id="color-names">
<h3>Color Names<a class="headerlink" href="#color-names" title="Permalink to this headline">¶</a></h3>
<p>See <a class="reference internal" href="ImageColor.html#color-names"><em>Color Names</em></a> for the color names supported by Pillow.</p>
</div>
<div class="section" id="fonts">
<h3>Fonts<a class="headerlink" href="#fonts" title="Permalink to this headline">¶</a></h3>
<p>PIL can use bitmap fonts or OpenType/TrueType fonts.</p>
<p>Bitmap fonts are stored in PIL’s own format, where each font typically consists
of a two files, one named .pil and the other usually named .pbm. The former
contains font metrics, the latter raster data.</p>
<p>To load a bitmap font, use the load functions in the <a class="reference internal" href="ImageFont.html#module-PIL.ImageFont" title="PIL.ImageFont"><tt class="xref py py-mod docutils literal"><span class="pre">ImageFont</span></tt></a>
module.</p>
<p>To load a OpenType/TrueType font, use the truetype function in the
<a class="reference internal" href="ImageFont.html#module-PIL.ImageFont" title="PIL.ImageFont"><tt class="xref py py-mod docutils literal"><span class="pre">ImageFont</span></tt></a> module. Note that this function depends on third-party
libraries, and may not available in all PIL builds.</p>
</div>
</div>
<div class="section" id="example-draw-partial-opacity-text">
<h2>Example: Draw Partial Opacity Text<a class="headerlink" href="#example-draw-partial-opacity-text" 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">ImageDraw</span><span class="p">,</span> <span class="n">ImageFont</span>
<span class="c"># get an image</span>
<span class="n">base</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;Pillow/Tests/images/lena.png&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">convert</span><span class="p">(</span><span class="s">&#39;RGBA&#39;</span><span class="p">)</span>

<span class="c"># make a blank image for the text, initialized to transparent text color</span>
<span class="n">txt</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="s">&#39;RGBA&#39;</span><span class="p">,</span> <span class="n">base</span><span class="o">.</span><span class="n">size</span><span class="p">,</span> <span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">0</span><span class="p">))</span>

<span class="c"># get a font</span>
<span class="n">fnt</span> <span class="o">=</span> <span class="n">ImageFont</span><span class="o">.</span><span class="n">truetype</span><span class="p">(</span><span class="s">&#39;Pillow/Tests/fonts/FreeMono.ttf&#39;</span><span class="p">,</span> <span class="mi">40</span><span class="p">)</span>
<span class="c"># get a drawing context</span>
<span class="n">d</span> <span class="o">=</span> <span class="n">ImageDraw</span><span class="o">.</span><span class="n">Draw</span><span class="p">(</span><span class="n">txt</span><span class="p">)</span>

<span class="c"># draw text, half opacity</span>
<span class="n">d</span><span class="o">.</span><span class="n">text</span><span class="p">((</span><span class="mi">10</span><span class="p">,</span><span class="mi">10</span><span class="p">),</span> <span class="s">&quot;Hello&quot;</span><span class="p">,</span> <span class="n">font</span><span class="o">=</span><span class="n">fnt</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">128</span><span class="p">))</span>
<span class="c"># draw text, full opacity</span>
<span class="n">d</span><span class="o">.</span><span class="n">text</span><span class="p">((</span><span class="mi">10</span><span class="p">,</span><span class="mi">60</span><span class="p">),</span> <span class="s">&quot;World&quot;</span><span class="p">,</span> <span class="n">font</span><span class="o">=</span><span class="n">fnt</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">))</span>

<span class="n">out</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">alpha_composite</span><span class="p">(</span><span class="n">base</span><span class="p">,</span> <span class="n">txt</span><span class="p">)</span>

<span class="n">out</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="functions">
<h2>Functions<a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw">
<em class="property">class </em><tt class="descclassname">PIL.ImageDraw.</tt><tt class="descname">Draw</tt><big>(</big><em>im</em>, <em>mode=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an object that can be used to draw in the given image.</p>
<p>Note that the image will be modified in place.</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"><ul class="first last simple">
<li><strong>im</strong> &#8211; The image to draw in.</li>
<li><strong>mode</strong> &#8211; Optional mode to use for color values.  For RGB
images, this argument can be RGB or RGBA (to blend the
drawing into the image).  For all other modes, this argument
must be the same as the image mode.  If omitted, the mode
defaults to the mode of the image.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="methods">
<h2>Methods<a class="headerlink" href="#methods" title="Permalink to this headline">¶</a></h2>
<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.arc">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">arc</tt><big>(</big><em>xy</em>, <em>start</em>, <em>end</em>, <em>fill=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.arc" title="Permalink to this definition">¶</a></dt>
<dd><p>Draws an arc (a portion of a circle outline) between the start and end
angles, inside the given bounding box.</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"><ul class="first last simple">
<li><strong>xy</strong> &#8211; Four points to define the bounding box. Sequence of
<tt class="docutils literal"><span class="pre">[(x0,</span> <span class="pre">y0),</span> <span class="pre">(x1,</span> <span class="pre">y1)]</span></tt> or <tt class="docutils literal"><span class="pre">[x0,</span> <span class="pre">y0,</span> <span class="pre">x1,</span> <span class="pre">y1]</span></tt>.</li>
<li><strong>start</strong> &#8211; Starting angle, in degrees. Angles are measured from
3 o&#8217;clock, increasing clockwise.</li>
<li><strong>end</strong> &#8211; Ending angle, in degrees.</li>
<li><strong>fill</strong> &#8211; Color to use for the arc.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.bitmap">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">bitmap</tt><big>(</big><em>xy</em>, <em>bitmap</em>, <em>fill=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.bitmap" title="Permalink to this definition">¶</a></dt>
<dd><p>Draws a bitmap (mask) at the given position, using the current fill color
for the non-zero portions. The bitmap should be a valid transparency mask
(mode “1”) or matte (mode “L” or “RGBA”).</p>
<p>This is equivalent to doing <tt class="docutils literal"><span class="pre">image.paste(xy,</span> <span class="pre">color,</span> <span class="pre">bitmap)</span></tt>.</p>
<p>To paste pixel data into an image, use the
<tt class="xref py py-meth docutils literal"><span class="pre">paste()</span></tt> method on the image itself.</p>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.chord">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">chord</tt><big>(</big><em>xy</em>, <em>start</em>, <em>end</em>, <em>fill=None</em>, <em>outline=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.chord" title="Permalink to this definition">¶</a></dt>
<dd><p>Same as <a class="reference internal" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.arc" title="PIL.ImageDraw.PIL.ImageDraw.Draw.arc"><tt class="xref py py-meth docutils literal"><span class="pre">arc()</span></tt></a>, but connects the end points
with a straight line.</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"><ul class="first last simple">
<li><strong>xy</strong> &#8211; Four points to define the bounding box. Sequence of
<tt class="docutils literal"><span class="pre">[(x0,</span> <span class="pre">y0),</span> <span class="pre">(x1,</span> <span class="pre">y1)]</span></tt> or <tt class="docutils literal"><span class="pre">[x0,</span> <span class="pre">y0,</span> <span class="pre">x1,</span> <span class="pre">y1]</span></tt>.</li>
<li><strong>outline</strong> &#8211; Color to use for the outline.</li>
<li><strong>fill</strong> &#8211; Color to use for the fill.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.ellipse">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">ellipse</tt><big>(</big><em>xy</em>, <em>fill=None</em>, <em>outline=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.ellipse" title="Permalink to this definition">¶</a></dt>
<dd><p>Draws an ellipse inside the given bounding box.</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"><ul class="first last simple">
<li><strong>xy</strong> &#8211; Four points to define the bounding box. Sequence of either
<tt class="docutils literal"><span class="pre">[(x0,</span> <span class="pre">y0),</span> <span class="pre">(x1,</span> <span class="pre">y1)]</span></tt> or <tt class="docutils literal"><span class="pre">[x0,</span> <span class="pre">y0,</span> <span class="pre">x1,</span> <span class="pre">y1]</span></tt>.</li>
<li><strong>outline</strong> &#8211; Color to use for the outline.</li>
<li><strong>fill</strong> &#8211; Color to use for the fill.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.line">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">line</tt><big>(</big><em>xy</em>, <em>fill=None</em>, <em>width=0</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.line" title="Permalink to this definition">¶</a></dt>
<dd><p>Draws a line between the coordinates in the <strong>xy</strong> list.</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"><ul class="first last simple">
<li><strong>xy</strong> &#8211; Sequence of either 2-tuples like <tt class="docutils literal"><span class="pre">[(x,</span> <span class="pre">y),</span> <span class="pre">(x,</span> <span class="pre">y),</span> <span class="pre">...]</span></tt> or
numeric values like <tt class="docutils literal"><span class="pre">[x,</span> <span class="pre">y,</span> <span class="pre">x,</span> <span class="pre">y,</span> <span class="pre">...]</span></tt>.</li>
<li><strong>fill</strong> &#8211; Color to use for the line.</li>
<li><strong>width</strong> &#8211; <p>The line width, in pixels. Note that line
joins are not handled well, so wide polylines will not look good.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.5.</span></p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This option was broken until version 1.1.6.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.pieslice">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">pieslice</tt><big>(</big><em>xy</em>, <em>start</em>, <em>end</em>, <em>fill=None</em>, <em>outline=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.pieslice" title="Permalink to this definition">¶</a></dt>
<dd><p>Same as arc, but also draws straight lines between the end points and the
center of the bounding box.</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"><ul class="first last simple">
<li><strong>xy</strong> &#8211; Four points to define the bounding box. Sequence of
<tt class="docutils literal"><span class="pre">[(x0,</span> <span class="pre">y0),</span> <span class="pre">(x1,</span> <span class="pre">y1)]</span></tt> or <tt class="docutils literal"><span class="pre">[x0,</span> <span class="pre">y0,</span> <span class="pre">x1,</span> <span class="pre">y1]</span></tt>.</li>
<li><strong>outline</strong> &#8211; Color to use for the outline.</li>
<li><strong>fill</strong> &#8211; Color to use for the fill.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.point">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">point</tt><big>(</big><em>xy</em>, <em>fill=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.point" title="Permalink to this definition">¶</a></dt>
<dd><p>Draws points (individual pixels) at the given coordinates.</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"><ul class="first last simple">
<li><strong>xy</strong> &#8211; Sequence of either 2-tuples like <tt class="docutils literal"><span class="pre">[(x,</span> <span class="pre">y),</span> <span class="pre">(x,</span> <span class="pre">y),</span> <span class="pre">...]</span></tt> or
numeric values like <tt class="docutils literal"><span class="pre">[x,</span> <span class="pre">y,</span> <span class="pre">x,</span> <span class="pre">y,</span> <span class="pre">...]</span></tt>.</li>
<li><strong>fill</strong> &#8211; Color to use for the point.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.polygon">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">polygon</tt><big>(</big><em>xy</em>, <em>fill=None</em>, <em>outline=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.polygon" title="Permalink to this definition">¶</a></dt>
<dd><p>Draws a polygon.</p>
<p>The polygon outline consists of straight lines between the given
coordinates, plus a straight line between the last and the first
coordinate.</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"><ul class="first last simple">
<li><strong>xy</strong> &#8211; Sequence of either 2-tuples like <tt class="docutils literal"><span class="pre">[(x,</span> <span class="pre">y),</span> <span class="pre">(x,</span> <span class="pre">y),</span> <span class="pre">...]</span></tt> or
numeric values like <tt class="docutils literal"><span class="pre">[x,</span> <span class="pre">y,</span> <span class="pre">x,</span> <span class="pre">y,</span> <span class="pre">...]</span></tt>.</li>
<li><strong>outline</strong> &#8211; Color to use for the outline.</li>
<li><strong>fill</strong> &#8211; Color to use for the fill.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.rectangle">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">rectangle</tt><big>(</big><em>xy</em>, <em>fill=None</em>, <em>outline=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.rectangle" title="Permalink to this definition">¶</a></dt>
<dd><p>Draws a rectangle.</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"><ul class="first last simple">
<li><strong>xy</strong> &#8211; Four points to define the bounding box. Sequence of either
<tt class="docutils literal"><span class="pre">[(x0,</span> <span class="pre">y0),</span> <span class="pre">(x1,</span> <span class="pre">y1)]</span></tt> or <tt class="docutils literal"><span class="pre">[x0,</span> <span class="pre">y0,</span> <span class="pre">x1,</span> <span class="pre">y1]</span></tt>. The second point
is just outside the drawn rectangle.</li>
<li><strong>outline</strong> &#8211; Color to use for the outline.</li>
<li><strong>fill</strong> &#8211; Color to use for the fill.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.shape">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">shape</tt><big>(</big><em>shape</em>, <em>fill=None</em>, <em>outline=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.shape" title="Permalink to this definition">¶</a></dt>
<dd><div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">This method is experimental.</p>
</div>
<p>Draw a shape.</p>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.text">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">text</tt><big>(</big><em>xy</em>, <em>text</em>, <em>fill=None</em>, <em>font=None</em>, <em>anchor=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.text" title="Permalink to this definition">¶</a></dt>
<dd><p>Draws the string at the given position.</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"><ul class="first last simple">
<li><strong>xy</strong> &#8211; Top left corner of the text.</li>
<li><strong>text</strong> &#8211; Text to be drawn.</li>
<li><strong>font</strong> &#8211; An <tt class="xref py py-class docutils literal"><span class="pre">ImageFont</span></tt> instance.</li>
<li><strong>fill</strong> &#8211; Color to use for the text.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.textsize">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">textsize</tt><big>(</big><em>text</em>, <em>font=None</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.textsize" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the size of the given string, in pixels.</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"><ul class="first last simple">
<li><strong>text</strong> &#8211; Text to be measured.</li>
<li><strong>font</strong> &#8211; An <tt class="xref py py-class docutils literal"><span class="pre">ImageFont</span></tt> instance.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="legacy-api">
<h2>Legacy API<a class="headerlink" href="#legacy-api" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#PIL.ImageDraw.PIL.ImageDraw.Draw" title="PIL.ImageDraw.PIL.ImageDraw.Draw"><tt class="xref py py-class docutils literal"><span class="pre">Draw</span></tt></a> class contains a constructor and a number
of methods which are provided for backwards compatibility only. For this to
work properly, you should either use options on the drawing primitives, or
these methods. Do not mix the old and new calling conventions.</p>
<dl class="function">
<dt id="PIL.ImageDraw.PIL.ImageDraw.ImageDraw">
<tt class="descclassname">PIL.ImageDraw.</tt><tt class="descname">ImageDraw</tt><big>(</big><em>image</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.ImageDraw" title="Permalink to this definition">¶</a></dt>
<dd><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">Return type:</th><td class="field-body"><a class="reference internal" href="#PIL.ImageDraw.PIL.ImageDraw.Draw" title="PIL.ImageDraw.PIL.ImageDraw.Draw"><tt class="xref py py-class docutils literal"><span class="pre">Draw</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.setink">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">setink</tt><big>(</big><em>ink</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.setink" title="Permalink to this definition">¶</a></dt>
<dd><div class="deprecated">
<p><span class="versionmodified">Deprecated since version 1.1.5.</span></p>
</div>
<p>Sets the color to use for subsequent draw and fill operations.</p>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.setfill">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">setfill</tt><big>(</big><em>fill</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.setfill" title="Permalink to this definition">¶</a></dt>
<dd><div class="deprecated">
<p><span class="versionmodified">Deprecated since version 1.1.5.</span></p>
</div>
<p>Sets the fill mode.</p>
<p>If the mode is 0, subsequently drawn shapes (like polygons and rectangles)
are outlined. If the mode is 1, they are filled.</p>
</dd></dl>

<dl class="method">
<dt id="PIL.ImageDraw.PIL.ImageDraw.Draw.setfont">
<tt class="descclassname">PIL.ImageDraw.Draw.</tt><tt class="descname">setfont</tt><big>(</big><em>font</em><big>)</big><a class="headerlink" href="#PIL.ImageDraw.PIL.ImageDraw.Draw.setfont" title="Permalink to this definition">¶</a></dt>
<dd><div class="deprecated">
<p><span class="versionmodified">Deprecated since version 1.1.5.</span></p>
</div>
<p>Sets the default font to use for the text method.</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>font</strong> &#8211; An <tt class="xref py py-class docutils literal"><span class="pre">ImageFont</span></tt> instance.</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">ImageDraw</span></tt> Module</a><ul>
<li><a class="reference internal" href="#example-draw-a-gray-cross-over-an-image">Example: Draw a gray cross over an image</a></li>
<li><a class="reference internal" href="#concepts">Concepts</a><ul>
<li><a class="reference internal" href="#coordinates">Coordinates</a></li>
<li><a class="reference internal" href="#colors">Colors</a></li>
<li><a class="reference internal" href="#color-names">Color Names</a></li>
<li><a class="reference internal" href="#fonts">Fonts</a></li>
</ul>
</li>
<li><a class="reference internal" href="#example-draw-partial-opacity-text">Example: Draw Partial Opacity Text</a></li>
<li><a class="reference internal" href="#functions">Functions</a></li>
<li><a class="reference internal" href="#methods">Methods</a></li>
<li><a class="reference internal" href="#legacy-api">Legacy API</a></li>
</ul>
</li>
</ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/reference/ImageDraw.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="ImageEnhance.html" title="ImageEnhance Module"
             >next</a> |</li>
        <li class="right" >
          <a href="ImageCms.html" title="ImageCms Module"
             >previous</a> |</li>
        <li><a href="../index.html">Home</a> &raquo;</li>
          <li><a href="index.html" >Reference</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>