Skip to content

Commit 45efec6

Browse files
committed
Image
1 parent 182c086 commit 45efec6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,7 @@ run(host='0.0.0.0', port=80, server='cherrypy')
24102410
```python
24112411
@route('/img/<image>')
24122412
def send_image(image):
2413-
return static_file(image, 'images/', mimetype='image/png')
2413+
return static_file(image, 'img_dir/', mimetype='image/png')
24142414
```
24152415

24162416
### Dynamic Request
@@ -2638,6 +2638,12 @@ from PIL import Image
26382638
<Image>.paste(<Image>, (x, y)) # Writes an image to image.
26392639
```
26402640

2641+
```bash
2642+
<2d_array> = np.array(<Image>) # NumPy array from greyscale image.
2643+
<3d_array> = np.array(<Image>) # NumPy array from color image.
2644+
<Image> = Image.fromarray(<array>) # Image from NumPy array.
2645+
```
2646+
26412647
### Modes
26422648
* **`'1'` - 1-bit pixels, black and white, stored with one pixel per byte.**
26432649
* **`'L'` - 8-bit pixels, greyscale.**

index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,7 @@
20732073

20742074
<div><h3 id="staticrequest">Static Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@route('/img/&lt;image&gt;')</span>
20752075
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">send_image</span><span class="hljs-params">(image)</span>:</span>
2076-
<span class="hljs-keyword">return</span> static_file(image, <span class="hljs-string">'images/'</span>, mimetype=<span class="hljs-string">'image/png'</span>)
2076+
<span class="hljs-keyword">return</span> static_file(image, <span class="hljs-string">'img_dir/'</span>, mimetype=<span class="hljs-string">'image/png'</span>)
20772077
</code></pre></div>
20782078

20792079
<div><h3 id="dynamicrequest">Dynamic Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@route('/&lt;sport&gt;')</span>
@@ -2244,6 +2244,10 @@
22442244
&lt;Image&gt;.putdata(&lt;list/ImagingCore&gt;) <span class="hljs-comment"># Writes a sequence of pixels.</span>
22452245
&lt;Image&gt;.paste(&lt;Image&gt;, (x, y)) <span class="hljs-comment"># Writes an image to image.</span>
22462246
</code></pre>
2247+
<pre><code class="bash language-bash hljs">&lt;2d_array&gt; = np.array(&lt;Image&gt;) <span class="hljs-comment"># NumPy array from greyscale image.</span>
2248+
&lt;3d_array&gt; = np.array(&lt;Image&gt;) <span class="hljs-comment"># NumPy array from color image.</span>
2249+
&lt;Image&gt; = Image.fromarray(&lt;array&gt;) <span class="hljs-comment"># Image from NumPy array.</span>
2250+
</code></pre>
22472251
<div><h3 id="modes-1">Modes</h3><ul>
22482252
<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>
22492253
<li><strong><code class="python hljs"><span class="hljs-string">'L'</span></code> - 8-bit pixels, greyscale.</strong></li>

0 commit comments

Comments
 (0)