<pre><codeclass="python language-python hljs"><tuple/int> = img.getpixel((x, y)) <spanclass="hljs-comment"># Returns a pixel.</span>
<Image>.putpixel((x, y), <tuple/int>) <spanclass="hljs-comment"># Writes tuple/int to image.</span>
<ImagingCore> = <Image>.getdata() <spanclass="hljs-comment"># Returns a sequence of tuples/ints.</span>
<Image>.putdata(<list/tuple>) <spanclass="hljs-comment"># Writes a sequence of tuples/ints.</span>
<Image>.paste(<Image>, (x, y)) <spanclass="hljs-comment"># Writes an image to image.</span>
</code></pre>
<div><h3id="modes-1">Modes</h3><ul>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'1'</span></code> - 1-bit pixels, black and white, stored with one pixel per byte.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'fill=<color>'</span></code> to set the primary color.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'outline=<color>'</span></code> to set the secondary color.</strong></li>
<li><strong>Colors can be specified as tuple, int, <codeclass="python hljs"><spanclass="hljs-string">'#rrggbb'</span></code> string or a color name.</strong></li>
</ul>
<div><h3id="examples">Examples</h3><div><h4id="createsapngimageofarainbowgradient">Creates a PNG image of a rainbow gradient:</h4><pre><codeclass="python language-python hljs">WIDTH, HEIGHT = <spanclass="hljs-number">100</span>, <spanclass="hljs-number">100</span>
<div><h3id="examples">Examples</h3><div><h4id="createsapngimageofarainbowgradient">Creates a PNG image of a rainbow gradient:</h4><pre><codeclass="python language-python hljs">WIDTH, HEIGHT = <spanclass="hljs-number">100</span>, <spanclass="hljs-number">100</span>
size = WIDTH * HEIGHT
size = WIDTH * HEIGHT
hue = [<spanclass="hljs-number">255</span> * i/size <spanclass="hljs-keyword">for</span> i <spanclass="hljs-keyword">in</span> range(size)]
hue = [<spanclass="hljs-number">255</span> * i/size <spanclass="hljs-keyword">for</span> i <spanclass="hljs-keyword">in</span> range(size)]
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'1'</span></code> - 1-bit pixels, black and white, stored with one pixel per byte.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'RGBA'</span></code> - 4x8-bit pixels, true color with transparency mask.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'HSV'</span></code> - 3x8-bit pixels, Hue, Saturation, Value color space.</strong></li>
</ul><div><h3id="animation">Animation</h3><div><h4id="createsagifofabouncingball">Creates a GIF of a bouncing ball:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-comment"># $ pip3 install imageio</span>
<div><h3id="animation">Animation</h3><div><h4id="createsagifofabouncingball">Creates a GIF of a bouncing ball:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-comment"># $ pip3 install imageio</span>