Browse Source

Image

pull/188/head
Jure Šorn 10 months ago
parent
commit
594c8dec94
2 changed files with 16 additions and 16 deletions
  1. 14
      README.md
  2. 18
      index.html

14
README.md

@ -2770,8 +2770,8 @@ from PIL import Image
```
```python
<Image> = Image.new('<mode>', (width, height)) # Also `color=<int/tuple/str>`.
<Image> = Image.open(<path>) # Identifies format based on file contents.
<Image> = Image.new('<mode>', (width, height)) # Creates new image. Also `color=<int/tuple>`.
<Image> = Image.open(<path>) # Identifies format based on file's contents.
<Image> = <Image>.convert('<mode>') # Converts image to the new mode.
<Image>.save(<path>) # Selects format based on the path extension.
<Image>.show() # Opens image in the default preview app.
@ -2782,7 +2782,7 @@ from PIL import Image
<Image>.putpixel((x, y), <int/tuple>) # Updates pixel's value.
<ImagingCore> = <Image>.getdata() # Returns a flattened view of pixel values.
<Image>.putdata(<list/ImagingCore>) # Updates pixels with a copy of the sequence.
<Image>.paste(<Image>, (x, y)) # Draws passed image at specified location.
<Image>.paste(<Image>, (x, y)) # Draws passed image at the specified location.
```
```python
@ -2796,10 +2796,10 @@ from PIL import Image
```
### Modes
* **`'L'` - 8-bit pixels, greyscale.**
* **`'RGB'` - 3x8-bit pixels, true color.**
* **`'RGBA'` - 4x8-bit pixels, true color with transparency mask.**
* **`'HSV'` - 3x8-bit pixels, Hue, Saturation, Value color space.**
* **`'L'` - Lightness (i.e. greyscale). Each pixel is an int between 0 and 255.**
* **`'RGB'` - Red, green, blue (i.e. true color). Each pixel is a tuple of three ints.**
* **`'RGBA'` - RGB with alpha. Low alpha (forth int) means more transparency.**
* **`'HSV'` - Hue, saturation, value color space.**
### Examples
#### Creates a PNG image of a rainbow gradient:

18
index.html

@ -54,7 +54,7 @@
<body>
<header>
<aside>May 18, 2024</aside>
<aside>June 18, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -2262,8 +2262,8 @@ right = [[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
</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>
&lt;Image&gt; = Image.open(&lt;path&gt;) <span class="hljs-comment"># Identifies format based on file contents.</span>
<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"># Creates new image. Also `color=&lt;int/tuple&gt;`.</span>
&lt;Image&gt; = Image.open(&lt;path&gt;) <span class="hljs-comment"># Identifies format based on file's contents.</span>
&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>
&lt;Image&gt;.save(&lt;path&gt;) <span class="hljs-comment"># Selects format based on the path extension.</span>
&lt;Image&gt;.show() <span class="hljs-comment"># Opens image in the default preview app.</span>
@ -2272,7 +2272,7 @@ right = [[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</
&lt;Image&gt;.putpixel((x, y), &lt;int/tuple&gt;) <span class="hljs-comment"># Updates pixel's value.</span>
&lt;ImagingCore&gt; = &lt;Image&gt;.getdata() <span class="hljs-comment"># Returns a flattened view of pixel values.</span>
&lt;Image&gt;.putdata(&lt;list/ImagingCore&gt;) <span class="hljs-comment"># Updates pixels with a copy of the sequence.</span>
&lt;Image&gt;.paste(&lt;Image&gt;, (x, y)) <span class="hljs-comment"># Draws passed image at specified location.</span>
&lt;Image&gt;.paste(&lt;Image&gt;, (x, y)) <span class="hljs-comment"># Draws passed image at the specified location.</span>
</code></pre>
<pre><code class="python language-python hljs">&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>
@ -2281,10 +2281,10 @@ right = [[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</
&lt;Image&gt; = Image.fromarray(np.uint8(&lt;array&gt;)) <span class="hljs-comment"># Use `&lt;array&gt;.clip(0, 255)` to clip values.</span>
</code></pre>
<div><h3 id="modes-1">Modes</h3><ul>
<li><strong><code class="python hljs"><span class="hljs-string">'L'</span></code> - 8-bit pixels, greyscale.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'RGB'</span></code> - 3x8-bit pixels, true color.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'RGBA'</span></code> - 4x8-bit pixels, true color with transparency mask.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'HSV'</span></code> - 3x8-bit pixels, Hue, Saturation, Value color space.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'L'</span></code> - Lightness (i.e. greyscale). Each pixel is an int between 0 and 255.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'RGB'</span></code> - Red, green, blue (i.e. true color). Each pixel is a tuple of three ints.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'RGBA'</span></code> - RGB with alpha. Low alpha (forth int) means more transparency.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'HSV'</span></code> - Hue, saturation, value color space.</strong></li>
</ul><div><h3 id="examples">Examples</h3><div><h4 id="createsapngimageofarainbowgradient">Creates a PNG image of a rainbow gradient:</h4><pre><code class="python language-python hljs">WIDTH, HEIGHT = <span class="hljs-number">100</span>, <span class="hljs-number">100</span>
n_pixels = WIDTH * HEIGHT
hues = (<span class="hljs-number">255</span> * i/n_pixels <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(n_pixels))
@ -2932,7 +2932,7 @@ $ deactivate <span class="hljs-comment"># Deactivates the activ
<footer>
<aside>May 18, 2024</aside>
<aside>June 18, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

|||||||
100:0
Loading…
Cancel
Save