diff --git a/README.md b/README.md index 8828f1d..4c11b1e 100644 --- a/README.md +++ b/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: diff --git a/index.html b/index.html index 0909a38..667cad6 100644 --- a/index.html +++ b/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"><Image> = Image.new(<span class="hljs-string">'<mode>'</span>, (width, height)) <span class="hljs-comment"># Also `color=<int/tuple/str>`.</span> -<Image> = Image.open(<path>) <span class="hljs-comment"># Identifies format based on file contents.</span> +<pre><code class="python language-python hljs"><Image> = Image.new(<span class="hljs-string">'<mode>'</span>, (width, height)) <span class="hljs-comment"># Creates new image. Also `color=<int/tuple>`.</span> +<Image> = Image.open(<path>) <span class="hljs-comment"># Identifies format based on file's contents.</span> <Image> = <Image>.convert(<span class="hljs-string">'<mode>'</span>) <span class="hljs-comment"># Converts image to the new mode.</span> <Image>.save(<path>) <span class="hljs-comment"># Selects format based on the path extension.</span> <Image>.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</ <Image>.putpixel((x, y), <int/tuple>) <span class="hljs-comment"># Updates pixel's value.</span> <ImagingCore> = <Image>.getdata() <span class="hljs-comment"># Returns a flattened view of pixel values.</span> <Image>.putdata(<list/ImagingCore>) <span class="hljs-comment"># Updates pixels with a copy of the sequence.</span> -<Image>.paste(<Image>, (x, y)) <span class="hljs-comment"># Draws passed image at specified location.</span> +<Image>.paste(<Image>, (x, y)) <span class="hljs-comment"># Draws passed image at the specified location.</span> </code></pre> <pre><code class="python language-python hljs"><Image> = <Image>.filter(<Filter>) <span class="hljs-comment"># `<Filter> = ImageFilter.<name>(<args>)`</span> <Image> = <Enhance>.enhance(<float>) <span class="hljs-comment"># `<Enhance> = ImageEnhance.<name>(<Image>)`</span> @@ -2281,10 +2281,10 @@ right = [[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</ <Image> = Image.fromarray(np.uint8(<array>)) <span class="hljs-comment"># Use `<array>.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>