Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e21c98

Browse files
committed
Image
1 parent 1ea4303 commit 9e21c98

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,25 +2732,25 @@ from PIL import Image
27322732
```
27332733

27342734
```python
2735-
<Image> = Image.new('<mode>', (width, height)) # Also: `color=<int/tuple/str>`.
2736-
<Image> = Image.open(<path>) # Identifies format based on file contents.
2737-
<Image> = <Image>.convert('<mode>') # Converts image to the new mode.
2738-
<Image>.save(<path>) # Selects format based on the path extension.
2739-
<Image>.show() # Opens image in default preview app.
2735+
<Image> = Image.new('<mode>', (width, height)) # Also: `color=<int/tuple/str>`.
2736+
<Image> = Image.open(<path>) # Identifies format based on file contents.
2737+
<Image> = <Image>.convert('<mode>') # Converts image to the new mode.
2738+
<Image>.save(<path>) # Selects format based on the path extension.
2739+
<Image>.show() # Opens image in default preview app.
27402740
```
27412741

27422742
```python
2743-
<int/tuple> = <Image>.getpixel((x, y)) # Returns a pixel.
2744-
<Image>.putpixel((x, y), <int/tuple>) # Writes a pixel to the image.
2745-
<ImagingCore> = <Image>.getdata() # Returns a flattened sequence of pixels.
2746-
<Image>.putdata(<list/ImagingCore>) # Writes a flattened sequence of pixels.
2747-
<Image>.paste(<Image>, (x, y)) # Writes passed image to the image.
2743+
<int/tuple> = <Image>.getpixel((x, y)) # Returns a pixel.
2744+
<Image>.putpixel((x, y), <int/tuple>) # Writes a pixel to the image.
2745+
<ImagingCore> = <Image>.getdata() # Returns a flattened sequence of pixels.
2746+
<Image>.putdata(<list/ImagingCore>) # Writes a flattened sequence of pixels.
2747+
<Image>.paste(<Image>, (x, y)) # Writes passed image to the image.
27482748
```
27492749

27502750
```bash
2751-
<2d_array> = np.array(<Image_L>) # Creates NumPy array from greyscale image.
2752-
<3d_array> = np.array(<Image_RGB>) # Creates NumPy array from color image.
2753-
<Image> = Image.fromarray(<array>) # Creates image from NumPy array of floats.
2751+
<2d_array> = np.array(<Image_L>) # Creates NumPy array from greyscale image.
2752+
<3d_array> = np.array(<Image_RGB/A>) # Creates NumPy array from color image.
2753+
<Image> = Image.fromarray(np.uint8(<array>)) # Use <array>.clip(0, 255) to clip the values.
27542754
```
27552755

27562756
### Modes
@@ -2787,12 +2787,12 @@ from PIL import ImageDraw
27872787
```
27882788

27892789
```python
2790-
<ImageDraw>.point((x, y)) # Truncates floats into ints.
2791-
<ImageDraw>.line((x1, y1, x2, y2 [, ...])) # To get anti-aliasing use Image's resize().
2792-
<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2) # Always draws in clockwise direction.
2793-
<ImageDraw>.rectangle((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste().
2794-
<ImageDraw>.polygon((x1, y1, x2, y2, ...)) # Last point gets connected to the first.
2795-
<ImageDraw>.ellipse((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste().
2790+
<ImageDraw>.point((x, y)) # Truncates floats into ints.
2791+
<ImageDraw>.line((x1, y1, x2, y2 [, ...])) # To get anti-aliasing use Image's resize().
2792+
<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2) # Always draws in clockwise direction.
2793+
<ImageDraw>.rectangle((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste().
2794+
<ImageDraw>.polygon((x1, y1, x2, y2, ...)) # Last point gets connected to the first.
2795+
<ImageDraw>.ellipse((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste().
27962796
```
27972797
* **Use `'fill=<color>'` to set the primary color.**
27982798
* **Use `'width=<int>'` to set the width of lines or contours.**

index.html

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<body>
5656
<header>
57-
<aside>July 29, 2022</aside>
57+
<aside>July 30, 2022</aside>
5858
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
5959
</header>
6060

@@ -2229,21 +2229,21 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
22292229
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
22302230
</code></pre></div>
22312231

2232-
<pre><code class="python language-python hljs">&lt;Image&gt; = Image.new(<span class="hljs-string">'&lt;mode&gt;'</span>, (width, height)) <span class="hljs-comment"># Also: `color=&lt;int/tuple/str&gt;`.</span>
2233-
&lt;Image&gt; = Image.open(&lt;path&gt;) <span class="hljs-comment"># Identifies format based on file contents.</span>
2234-
&lt;Image&gt; = &lt;Image&gt;.convert(<span class="hljs-string">'&lt;mode&gt;'</span>) <span class="hljs-comment"># Converts image to the new mode.</span>
2235-
&lt;Image&gt;.save(&lt;path&gt;) <span class="hljs-comment"># Selects format based on the path extension.</span>
2236-
&lt;Image&gt;.show() <span class="hljs-comment"># Opens image in default preview app.</span>
2232+
<pre><code class="python language-python hljs">&lt;Image&gt; = Image.new(<span class="hljs-string">'&lt;mode&gt;'</span>, (width, height)) <span class="hljs-comment"># Also: `color=&lt;int/tuple/str&gt;`.</span>
2233+
&lt;Image&gt; = Image.open(&lt;path&gt;) <span class="hljs-comment"># Identifies format based on file contents.</span>
2234+
&lt;Image&gt; = &lt;Image&gt;.convert(<span class="hljs-string">'&lt;mode&gt;'</span>) <span class="hljs-comment"># Converts image to the new mode.</span>
2235+
&lt;Image&gt;.save(&lt;path&gt;) <span class="hljs-comment"># Selects format based on the path extension.</span>
2236+
&lt;Image&gt;.show() <span class="hljs-comment"># Opens image in default preview app.</span>
22372237
</code></pre>
2238-
<pre><code class="python language-python hljs">&lt;int/tuple&gt; = &lt;Image&gt;.getpixel((x, y)) <span class="hljs-comment"># Returns a pixel.</span>
2239-
&lt;Image&gt;.putpixel((x, y), &lt;int/tuple&gt;) <span class="hljs-comment"># Writes a pixel to the image.</span>
2240-
&lt;ImagingCore&gt; = &lt;Image&gt;.getdata() <span class="hljs-comment"># Returns a flattened sequence of pixels.</span>
2241-
&lt;Image&gt;.putdata(&lt;list/ImagingCore&gt;) <span class="hljs-comment"># Writes a flattened sequence of pixels.</span>
2242-
&lt;Image&gt;.paste(&lt;Image&gt;, (x, y)) <span class="hljs-comment"># Writes passed image to the image.</span>
2238+
<pre><code class="python language-python hljs">&lt;int/tuple&gt; = &lt;Image&gt;.getpixel((x, y)) <span class="hljs-comment"># Returns a pixel.</span>
2239+
&lt;Image&gt;.putpixel((x, y), &lt;int/tuple&gt;) <span class="hljs-comment"># Writes a pixel to the image.</span>
2240+
&lt;ImagingCore&gt; = &lt;Image&gt;.getdata() <span class="hljs-comment"># Returns a flattened sequence of pixels.</span>
2241+
&lt;Image&gt;.putdata(&lt;list/ImagingCore&gt;) <span class="hljs-comment"># Writes a flattened sequence of pixels.</span>
2242+
&lt;Image&gt;.paste(&lt;Image&gt;, (x, y)) <span class="hljs-comment"># Writes passed image to the image.</span>
22432243
</code></pre>
2244-
<pre><code class="bash language-bash hljs">&lt;2d_array&gt; = np.array(&lt;Image_L&gt;) <span class="hljs-comment"># Creates NumPy array from greyscale image.</span>
2245-
&lt;3d_array&gt; = np.array(&lt;Image_RGB&gt;) <span class="hljs-comment"># Creates NumPy array from color image.</span>
2246-
&lt;Image&gt; = Image.fromarray(&lt;array&gt;) <span class="hljs-comment"># Creates image from NumPy array of floats.</span>
2244+
<pre><code class="bash language-bash hljs">&lt;2d_array&gt; = np.array(&lt;Image_L&gt;) <span class="hljs-comment"># Creates NumPy array from greyscale image.</span>
2245+
&lt;3d_array&gt; = np.array(&lt;Image_RGB/A&gt;) <span class="hljs-comment"># Creates NumPy array from color image.</span>
2246+
&lt;Image&gt; = Image.fromarray(np.uint8(&lt;array&gt;)) <span class="hljs-comment"># Use &lt;array&gt;.clip(0, 255) to clip the values.</span>
22472247
</code></pre>
22482248
<div><h3 id="modes-1">Modes</h3><ul>
22492249
<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
22732273
&lt;ImageDraw&gt; = ImageDraw.Draw(&lt;Image&gt;)
22742274
</code></pre></div>
22752275

2276-
<pre><code class="python language-python hljs">&lt;ImageDraw&gt;.point((x, y)) <span class="hljs-comment"># Truncates floats into ints.</span>
2277-
&lt;ImageDraw&gt;.line((x1, y1, x2, y2 [, ...])) <span class="hljs-comment"># To get anti-aliasing use Image's resize().</span>
2278-
&lt;ImageDraw&gt;.arc((x1, y1, x2, y2), deg1, deg2) <span class="hljs-comment"># Always draws in clockwise direction.</span>
2279-
&lt;ImageDraw&gt;.rectangle((x1, y1, x2, y2)) <span class="hljs-comment"># To rotate use Image's rotate() and paste().</span>
2280-
&lt;ImageDraw&gt;.polygon((x1, y1, x2, y2, ...)) <span class="hljs-comment"># Last point gets connected to the first.</span>
2281-
&lt;ImageDraw&gt;.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">&lt;ImageDraw&gt;.point((x, y)) <span class="hljs-comment"># Truncates floats into ints.</span>
2277+
&lt;ImageDraw&gt;.line((x1, y1, x2, y2 [, ...])) <span class="hljs-comment"># To get anti-aliasing use Image's resize().</span>
2278+
&lt;ImageDraw&gt;.arc((x1, y1, x2, y2), deg1, deg2) <span class="hljs-comment"># Always draws in clockwise direction.</span>
2279+
&lt;ImageDraw&gt;.rectangle((x1, y1, x2, y2)) <span class="hljs-comment"># To rotate use Image's rotate() and paste().</span>
2280+
&lt;ImageDraw&gt;.polygon((x1, y1, x2, y2, ...)) <span class="hljs-comment"># Last point gets connected to the first.</span>
2281+
&lt;ImageDraw&gt;.ellipse((x1, y1, x2, y2)) <span class="hljs-comment"># To rotate use Image's rotate() and paste().</span>
22822282
</code></pre>
22832283
<ul>
22842284
<li><strong>Use <code class="python hljs"><span class="hljs-string">'fill=&lt;color&gt;'</span></code> to set the primary color.</strong></li>
@@ -2906,7 +2906,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29062906

29072907

29082908
<footer>
2909-
<aside>July 29, 2022</aside>
2909+
<aside>July 30, 2022</aside>
29102910
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29112911
</footer>
29122912

0 commit comments

Comments
 (0)