Browse Source

Image

pull/152/head
Jure Šorn 1 year ago
parent
commit
50e35c4c97
2 changed files with 21 additions and 19 deletions
  1. 19
      README.md
  2. 21
      index.html

19
README.md

@ -2740,7 +2740,7 @@ Image
-----
```python
# $ pip3 install pillow
from PIL import Image, ImageDraw
from PIL import Image, ImageFilter, ImageEnhance, ImageDraw
```
```python
@ -2759,13 +2759,16 @@ from PIL import Image, ImageDraw
<Image>.paste(<Image>, (x, y)) # Writes passed image to the image.
```
```bash
<2d_array> = np.array(<Image_L>) # Creates NumPy array from greyscale image.
<3d_array> = np.array(<Image_RGB/A>) # Creates NumPy array from color image.
<Image> = Image.fromarray(np.uint8(<array>)) # Use <array>.clip(0, 255) to clip the values.
```python
<Image> = <Image>.resize((width, height)) # Use <Image>.width/height for original sizes.
<Image> = <Image>.filter(<Filter>) # `<Filter> = ImageFilter.<name>([<args>])`
<Image> = <Enhance>.enhance(<float>) # `<Enhance> = ImageEnhance.<name>(<Image>)`
```
```python
<array> = np.array(<Image>) # Creates NumPy array from the image.
<Image> = Image.fromarray(np.uint8(<array>)) # Use <array>.clip(0, 255) to clip the values.
```
* **To edit an image use `'ImageEnhance'`, `'ImageFilter'` and `'ImageOps'` submodules.**
* **Custom filters can be applied to arrays using `'scipy.ndimage.convolve()'` function.**
### Modes
* **`'1'` - 1-bit pixels, black and white, stored with one pixel per byte.**
@ -2797,7 +2800,7 @@ img.show()
### Image Draw
```python
<ImageDraw> = ImageDraw.Draw(<Image>) # Object for adding 2D graphics to the image.
<ImageDraw>.point((x, y)) # Truncates floats into ints.
<ImageDraw>.point((x, y)) # Draws a point. Truncates floats into ints.
<ImageDraw>.line((x1, y1, x2, y2 [, ...])) # To get anti-aliasing use Image's resize().
<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2) # Always draws in clockwise direction.
<ImageDraw>.rectangle((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste().

21
index.html

@ -54,7 +54,7 @@
<body>
<header>
<aside>February 1, 2023</aside>
<aside>February 2, 2023</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -2240,7 +2240,7 @@ right = [[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</
<div><h2 id="image"><a href="#image" name="image">#</a>Image</h2><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install pillow</span>
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image, ImageDraw
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image, ImageFilter, ImageEnhance, ImageDraw
</code></pre></div>
<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>
@ -2255,14 +2255,13 @@ right = [[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</
&lt;Image&gt;.putdata(&lt;list/ImagingCore&gt;) <span class="hljs-comment"># Writes a flattened sequence of pixels.</span>
&lt;Image&gt;.paste(&lt;Image&gt;, (x, y)) <span class="hljs-comment"># Writes passed image to the image.</span>
</code></pre>
<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>
&lt;3d_array&gt; = np.array(&lt;Image_RGB/A&gt;) <span class="hljs-comment"># Creates NumPy array from color image.</span>
&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>
<pre><code class="python language-python hljs">&lt;Image&gt; = &lt;Image&gt;.resize((width, height)) <span class="hljs-comment"># Use &lt;Image&gt;.width/height for original sizes.</span>
&lt;Image&gt; = &lt;Image&gt;.filter(&lt;Filter&gt;) <span class="hljs-comment"># `&lt;Filter&gt; = ImageFilter.&lt;name&gt;([&lt;args&gt;])`</span>
&lt;Image&gt; = &lt;Enhance&gt;.enhance(&lt;float&gt;) <span class="hljs-comment"># `&lt;Enhance&gt; = ImageEnhance.&lt;name&gt;(&lt;Image&gt;)`</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;array&gt; = np.array(&lt;Image&gt;) <span class="hljs-comment"># Creates NumPy array from the image.</span>
&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>
</code></pre>
<ul>
<li><strong>To edit an image use <code class="python hljs"><span class="hljs-string">'ImageEnhance'</span></code>, <code class="python hljs"><span class="hljs-string">'ImageFilter'</span></code> and <code class="python hljs"><span class="hljs-string">'ImageOps'</span></code> submodules.</strong></li>
<li><strong>Custom filters can be applied to arrays using <code class="python hljs"><span class="hljs-string">'scipy.ndimage.convolve()'</span></code> function.</strong></li>
</ul>
<div><h3 id="modes-1">Modes</h3><ul>
<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>
<li><strong><code class="python hljs"><span class="hljs-string">'L'</span></code> - 8-bit pixels, greyscale.</strong></li>
@ -2288,7 +2287,7 @@ img.show()
</code></pre></div>
<div><h3 id="imagedraw">Image Draw</h3><pre><code class="python language-python hljs">&lt;ImageDraw&gt; = ImageDraw.Draw(&lt;Image&gt;) <span class="hljs-comment"># Object for adding 2D graphics to the image.</span>
&lt;ImageDraw&gt;.point((x, y)) <span class="hljs-comment"># Truncates floats into ints.</span>
&lt;ImageDraw&gt;.point((x, y)) <span class="hljs-comment"># Draws a point. Truncates floats into ints.</span>
&lt;ImageDraw&gt;.line((x1, y1, x2, y2 [, ...])) <span class="hljs-comment"># To get anti-aliasing use Image's resize().</span>
&lt;ImageDraw&gt;.arc((x1, y1, x2, y2), deg1, deg2) <span class="hljs-comment"># Always draws in clockwise direction.</span>
&lt;ImageDraw&gt;.rectangle((x1, y1, x2, y2)) <span class="hljs-comment"># To rotate use Image's rotate() and paste().</span>
@ -2924,7 +2923,7 @@ $ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment">
<footer>
<aside>February 1, 2023</aside>
<aside>February 2, 2023</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

Loading…
Cancel
Save