|
54 | 54 |
|
55 | 55 | <body>
|
56 | 56 | <header>
|
57 |
| - <aside>July 29, 2022</aside> |
| 57 | + <aside>July 30, 2022</aside> |
58 | 58 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
59 | 59 | </header>
|
60 | 60 |
|
@@ -2229,21 +2229,21 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
|
2229 | 2229 | <span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
|
2230 | 2230 | </code></pre></div>
|
2231 | 2231 |
|
2232 |
| -<pre><code class="python language-python hljs"><Image> = Image.new(<span class="hljs-string">'<mode>'</span>, (width, height)) <span class="hljs-comment"># Also: `color=<int/tuple/str>`.</span> |
2233 |
| -<Image> = Image.open(<path>) <span class="hljs-comment"># Identifies format based on file contents.</span> |
2234 |
| -<Image> = <Image>.convert(<span class="hljs-string">'<mode>'</span>) <span class="hljs-comment"># Converts image to the new mode.</span> |
2235 |
| -<Image>.save(<path>) <span class="hljs-comment"># Selects format based on the path extension.</span> |
2236 |
| -<Image>.show() <span class="hljs-comment"># Opens image in default preview app.</span> |
| 2232 | +<pre><code class="python language-python hljs"><Image> = Image.new(<span class="hljs-string">'<mode>'</span>, (width, height)) <span class="hljs-comment"># Also: `color=<int/tuple/str>`.</span> |
| 2233 | +<Image> = Image.open(<path>) <span class="hljs-comment"># Identifies format based on file contents.</span> |
| 2234 | +<Image> = <Image>.convert(<span class="hljs-string">'<mode>'</span>) <span class="hljs-comment"># Converts image to the new mode.</span> |
| 2235 | +<Image>.save(<path>) <span class="hljs-comment"># Selects format based on the path extension.</span> |
| 2236 | +<Image>.show() <span class="hljs-comment"># Opens image in default preview app.</span> |
2237 | 2237 | </code></pre>
|
2238 |
| -<pre><code class="python language-python hljs"><int/tuple> = <Image>.getpixel((x, y)) <span class="hljs-comment"># Returns a pixel.</span> |
2239 |
| -<Image>.putpixel((x, y), <int/tuple>) <span class="hljs-comment"># Writes a pixel to the image.</span> |
2240 |
| -<ImagingCore> = <Image>.getdata() <span class="hljs-comment"># Returns a flattened sequence of pixels.</span> |
2241 |
| -<Image>.putdata(<list/ImagingCore>) <span class="hljs-comment"># Writes a flattened sequence of pixels.</span> |
2242 |
| -<Image>.paste(<Image>, (x, y)) <span class="hljs-comment"># Writes passed image to the image.</span> |
| 2238 | +<pre><code class="python language-python hljs"><int/tuple> = <Image>.getpixel((x, y)) <span class="hljs-comment"># Returns a pixel.</span> |
| 2239 | +<Image>.putpixel((x, y), <int/tuple>) <span class="hljs-comment"># Writes a pixel to the image.</span> |
| 2240 | +<ImagingCore> = <Image>.getdata() <span class="hljs-comment"># Returns a flattened sequence of pixels.</span> |
| 2241 | +<Image>.putdata(<list/ImagingCore>) <span class="hljs-comment"># Writes a flattened sequence of pixels.</span> |
| 2242 | +<Image>.paste(<Image>, (x, y)) <span class="hljs-comment"># Writes passed image to the image.</span> |
2243 | 2243 | </code></pre>
|
2244 |
| -<pre><code class="bash language-bash hljs"><2d_array> = np.array(<Image_L>) <span class="hljs-comment"># Creates NumPy array from greyscale image.</span> |
2245 |
| -<3d_array> = np.array(<Image_RGB>) <span class="hljs-comment"># Creates NumPy array from color image.</span> |
2246 |
| -<Image> = Image.fromarray(<array>) <span class="hljs-comment"># Creates image from NumPy array of floats.</span> |
| 2244 | +<pre><code class="bash language-bash hljs"><2d_array> = np.array(<Image_L>) <span class="hljs-comment"># Creates NumPy array from greyscale image.</span> |
| 2245 | +<3d_array> = np.array(<Image_RGB/A>) <span class="hljs-comment"># Creates NumPy array from color image.</span> |
| 2246 | +<Image> = Image.fromarray(np.uint8(<array>)) <span class="hljs-comment"># Use <array>.clip(0, 255) to clip the values.</span> |
2247 | 2247 | </code></pre>
|
2248 | 2248 | <div><h3 id="modes-1">Modes</h3><ul>
|
2249 | 2249 | <li><strong><code class="python hljs"><span class="hljs-string">'1'</span></code> - 1-bit pixels, black and white, stored with one pixel per byte.</strong></li>
|
@@ -2273,12 +2273,12 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
|
2273 | 2273 | <ImageDraw> = ImageDraw.Draw(<Image>)
|
2274 | 2274 | </code></pre></div>
|
2275 | 2275 |
|
2276 |
| -<pre><code class="python language-python hljs"><ImageDraw>.point((x, y)) <span class="hljs-comment"># Truncates floats into ints.</span> |
2277 |
| -<ImageDraw>.line((x1, y1, x2, y2 [, ...])) <span class="hljs-comment"># To get anti-aliasing use Image's resize().</span> |
2278 |
| -<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2) <span class="hljs-comment"># Always draws in clockwise direction.</span> |
2279 |
| -<ImageDraw>.rectangle((x1, y1, x2, y2)) <span class="hljs-comment"># To rotate use Image's rotate() and paste().</span> |
2280 |
| -<ImageDraw>.polygon((x1, y1, x2, y2, ...)) <span class="hljs-comment"># Last point gets connected to the first.</span> |
2281 |
| -<ImageDraw>.ellipse((x1, y1, x2, y2)) <span class="hljs-comment"># To rotate use Image's rotate() and paste().</span> |
| 2276 | +<pre><code class="python language-python hljs"><ImageDraw>.point((x, y)) <span class="hljs-comment"># Truncates floats into ints.</span> |
| 2277 | +<ImageDraw>.line((x1, y1, x2, y2 [, ...])) <span class="hljs-comment"># To get anti-aliasing use Image's resize().</span> |
| 2278 | +<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2) <span class="hljs-comment"># Always draws in clockwise direction.</span> |
| 2279 | +<ImageDraw>.rectangle((x1, y1, x2, y2)) <span class="hljs-comment"># To rotate use Image's rotate() and paste().</span> |
| 2280 | +<ImageDraw>.polygon((x1, y1, x2, y2, ...)) <span class="hljs-comment"># Last point gets connected to the first.</span> |
| 2281 | +<ImageDraw>.ellipse((x1, y1, x2, y2)) <span class="hljs-comment"># To rotate use Image's rotate() and paste().</span> |
2282 | 2282 | </code></pre>
|
2283 | 2283 | <ul>
|
2284 | 2284 | <li><strong>Use <code class="python hljs"><span class="hljs-string">'fill=<color>'</span></code> to set the primary color.</strong></li>
|
@@ -2906,7 +2906,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
|
2906 | 2906 |
|
2907 | 2907 |
|
2908 | 2908 | <footer>
|
2909 |
| - <aside>July 29, 2022</aside> |
| 2909 | + <aside>July 30, 2022</aside> |
2910 | 2910 | <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
|
2911 | 2911 | </footer>
|
2912 | 2912 |
|
|
0 commit comments