<Image> = Image.open(<path>) <spanclass="hljs-comment"># Identifies format based on file contents.</span>
<Image> = <Image>.convert(<spanclass="hljs-string">'<mode>'</span>) <spanclass="hljs-comment"># Converts image to the new mode.</span>
<Image>.save(<path>) <spanclass="hljs-comment"># Selects format based on the path extension.</span>
<Image>.show() <spanclass="hljs-comment"># Opens image in default preview app.</span>
<Image> = Image.open(<path>) <spanclass="hljs-comment"># Identifies format based on file contents.</span>
<Image> = <Image>.convert(<spanclass="hljs-string">'<mode>'</span>) <spanclass="hljs-comment"># Converts image to the new mode.</span>
<Image>.save(<path>) <spanclass="hljs-comment"># Selects format based on the path extension.</span>
<Image>.show() <spanclass="hljs-comment"># Opens image in default preview app.</span>
</code></pre>
<pre><codeclass="python language-python hljs"><int/tuple> = <Image>.getpixel((x, y)) <spanclass="hljs-comment"># Returns a pixel.</span>
<Image>.putpixel((x, y), <int/tuple>) <spanclass="hljs-comment"># Writes a pixel to the image.</span>
<ImagingCore> = <Image>.getdata() <spanclass="hljs-comment"># Returns a flattened sequence of pixels.</span>
<Image>.putdata(<list/ImagingCore>) <spanclass="hljs-comment"># Writes a flattened sequence of pixels.</span>
<Image>.paste(<Image>, (x, y)) <spanclass="hljs-comment"># Writes passed image to the image.</span>
<pre><codeclass="python language-python hljs"><int/tuple> = <Image>.getpixel((x, y)) <spanclass="hljs-comment"># Returns a pixel.</span>
<Image>.putpixel((x, y), <int/tuple>) <spanclass="hljs-comment"># Writes a pixel to the image.</span>
<ImagingCore> = <Image>.getdata() <spanclass="hljs-comment"># Returns a flattened sequence of pixels.</span>
<Image>.putdata(<list/ImagingCore>) <spanclass="hljs-comment"># Writes a flattened sequence of pixels.</span>
<Image>.paste(<Image>, (x, y)) <spanclass="hljs-comment"># Writes passed image to the image.</span>
<3d_array> = np.array(<Image_RGB/A>) <spanclass="hljs-comment"># Creates NumPy array from color image.</span>
<Image> = Image.fromarray(np.uint8(<array>))<spanclass="hljs-comment"># Use <array>.clip(0, 255) to clip the values.</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>