You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<pre><codeclass="python language-python hljs"><Image> = Image.new(<spanclass="hljs-string">'<mode>'</span>, (width, height)) <spanclass="hljs-comment"># Also `color=<int/tuple/str>`.</span>
2266
-
<Image> = Image.open(<path>) <spanclass="hljs-comment"># Identifies format based on file contents.</span>
2265
+
<pre><codeclass="python language-python hljs"><Image> = Image.new(<spanclass="hljs-string">'<mode>'</span>, (width, height)) <spanclass="hljs-comment"># Creates new image. Also `color=<int/tuple>`.</span>
2266
+
<Image> = Image.open(<path>) <spanclass="hljs-comment"># Identifies format based on file's contents.</span>
2267
2267
<Image> = <Image>.convert(<spanclass="hljs-string">'<mode>'</span>) <spanclass="hljs-comment"># Converts image to the new mode.</span>
2268
2268
<Image>.save(<path>) <spanclass="hljs-comment"># Selects format based on the path extension.</span>
2269
2269
<Image>.show() <spanclass="hljs-comment"># Opens image in the default preview app.</span>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'RGBA'</span></code> - 4x8-bit pixels, true color with transparency mask.</strong></li>
2287
-
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'HSV'</span></code> - 3x8-bit pixels, Hue, Saturation, Value color space.</strong></li>
2284
+
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'L'</span></code> - Lightness (i.e. greyscale). Each pixel is an int between 0 and 255.</strong></li>
2285
+
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'RGB'</span></code> - Red, green, blue (i.e. true color). Each pixel is a tuple of three ints.</strong></li>
2286
+
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'RGBA'</span></code> - RGB with alpha. Low alpha (forth int) means more transparency.</strong></li>
2287
+
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'HSV'</span></code> - Hue, saturation, value color space.</strong></li>
2288
2288
</ul><div><h3id="examples">Examples</h3><div><h4id="createsapngimageofarainbowgradient">Creates a PNG image of a rainbow gradient:</h4><pre><codeclass="python language-python hljs">WIDTH, HEIGHT = <spanclass="hljs-number">100</span>, <spanclass="hljs-number">100</span>
2289
2289
n_pixels = WIDTH * HEIGHT
2290
2290
hues = (<spanclass="hljs-number">255</span> * i/n_pixels <spanclass="hljs-keyword">for</span> i <spanclass="hljs-keyword">in</span> range(n_pixels))
0 commit comments