You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<Image> = Image.open(<path>) <spanclass="hljs-comment"># Identifies format based on file contents.</span>
2248
-
<Image> = <Image>.convert(<spanclass="hljs-string">'<mode>'</span>) <spanclass="hljs-comment"># Converts image to the new mode.</span>
2249
-
<Image>.save(<path>) <spanclass="hljs-comment"># Selects format based on the path extension.</span>
2250
-
<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>
2248
+
<Image> = <Image>.convert(<spanclass="hljs-string">'<mode>'</span>) <spanclass="hljs-comment"># Converts image to the new mode.</span>
2249
+
<Image>.save(<path>) <spanclass="hljs-comment"># Selects format based on the path extension.</span>
2250
+
<Image>.show() <spanclass="hljs-comment"># Opens image in default preview app.</span>
2251
2251
</code></pre>
2252
-
<pre><codeclass="python language-python hljs"><int/tuple> = <Image>.getpixel((x, y)) <spanclass="hljs-comment"># Returns a pixel.</span>
2253
-
<Image>.putpixel((x, y), <int/tuple>) <spanclass="hljs-comment"># Writes a pixel to the image.</span>
2254
-
<ImagingCore> = <Image>.getdata() <spanclass="hljs-comment"># Returns a flattened sequence of pixels.</span>
2255
-
<Image>.putdata(<list/ImagingCore>) <spanclass="hljs-comment"># Writes a flattened sequence of pixels.</span>
2256
-
<Image>.paste(<Image>, (x, y)) <spanclass="hljs-comment"># Writes passed image to the image.</span>
2252
+
<pre><codeclass="python language-python hljs"><int/tuple> = <Image>.getpixel((x, y)) <spanclass="hljs-comment"># Returns a pixel.</span>
2253
+
<Image>.putpixel((x, y), <int/tuple>) <spanclass="hljs-comment"># Writes a pixel to the image.</span>
2254
+
<ImagingCore> = <Image>.getdata() <spanclass="hljs-comment"># Returns a flattened sequence of pixels.</span>
2255
+
<Image>.putdata(<list/ImagingCore>) <spanclass="hljs-comment"># Writes a flattened sequence of pixels.</span>
2256
+
<Image>.paste(<Image>, (x, y)) <spanclass="hljs-comment"># Writes passed image to the image.</span>
2257
2257
</code></pre>
2258
-
<pre><codeclass="python language-python hljs"><Image> = <Image>.resize((width, height)) <spanclass="hljs-comment"># Use <Image>.width/height for original sizes.</span>
<pre><codeclass="python language-python hljs"><Image> = <Image>.resize((width, height)) <spanclass="hljs-comment"># Use <Image>.width/height for original sizes.</span>
<pre><codeclass="python language-python hljs"><array> = np.array(<Image>) <spanclass="hljs-comment"># Creates NumPy array from the image.</span>
2263
-
<Image> = Image.fromarray(np.uint8(<array>)) <spanclass="hljs-comment"># Use <array>.clip(0, 255) to clip the values.</span>
2262
+
<pre><codeclass="python language-python hljs"><array> = np.array(<Image>) <spanclass="hljs-comment"># Creates NumPy array from the image.</span>
2263
+
<Image> = Image.fromarray(np.uint8(<array>)) <spanclass="hljs-comment"># Use <array>.clip(0, 255) to clip the values.</span>
2264
2264
</code></pre>
2265
2265
<div><h3id="modes-1">Modes</h3><ul>
2266
2266
<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>
<div><h3id="imagedraw">Image Draw</h3><pre><codeclass="python language-python hljs"><ImageDraw> = ImageDraw.Draw(<Image>) <spanclass="hljs-comment"># Object for adding 2D graphics to the image.</span>
2290
-
<ImageDraw>.point((x, y)) <spanclass="hljs-comment"># Draws a point. Truncates floats into ints.</span>
2291
-
<ImageDraw>.line((x1, y1, x2, y2 [, ...])) <spanclass="hljs-comment"># To get anti-aliasing use Image's resize().</span>
2292
-
<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2) <spanclass="hljs-comment"># Always draws in clockwise direction.</span>
2293
-
<ImageDraw>.rectangle((x1, y1, x2, y2)) <spanclass="hljs-comment"># To rotate use Image's rotate() and paste().</span>
2294
-
<ImageDraw>.polygon((x1, y1, x2, y2, ...)) <spanclass="hljs-comment"># Last point gets connected to the first.</span>
2295
-
<ImageDraw>.ellipse((x1, y1, x2, y2)) <spanclass="hljs-comment"># To rotate use Image's rotate() and paste().</span>
2289
+
<div><h3id="imagedraw">Image Draw</h3><pre><codeclass="python language-python hljs"><ImageDraw> = ImageDraw.Draw(<Image>) <spanclass="hljs-comment"># Object for adding 2D graphics to the image.</span>
2290
+
<ImageDraw>.point((x, y)) <spanclass="hljs-comment"># Draws a point. Truncates floats into ints.</span>
2291
+
<ImageDraw>.line((x1, y1, x2, y2 [, ...])) <spanclass="hljs-comment"># To get anti-aliasing use Image's resize().</span>
2292
+
<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2) <spanclass="hljs-comment"># Always draws in clockwise direction.</span>
2293
+
<ImageDraw>.rectangle((x1, y1, x2, y2)) <spanclass="hljs-comment"># To rotate use Image's rotate() and paste().</span>
2294
+
<ImageDraw>.polygon((x1, y1, x2, y2, ...)) <spanclass="hljs-comment"># Last point gets connected to the first.</span>
2295
+
<ImageDraw>.ellipse((x1, y1, x2, y2)) <spanclass="hljs-comment"># To rotate use Image's rotate() and paste().</span>
0 commit comments