Skip to content

Commit 413eac0

Browse files
committed
Image
1 parent 8e988ff commit 413eac0

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,24 @@ img.convert(mode='RGB').save('test.png')
25902590
* **`'RGBA'` - 4x8-bit pixels, true color with transparency mask.**
25912591
* **`'HSV'` - 3x8-bit pixels, Hue, Saturation, Value color space.**
25922592

2593+
### Animation
2594+
2595+
#### Creates a GIF of a bouncing ball:
2596+
```python
2597+
from PIL import Image, ImageDraw
2598+
import imageio
2599+
height, r = 126, 10
2600+
frames = []
2601+
for velocity in range(1, 16):
2602+
y = sum(range(velocity))
2603+
frame = Image.new('L', (height, height))
2604+
draw = ImageDraw.Draw(frame)
2605+
draw.ellipse((height/2-r, y, height/2+r, y+2*r), fill='white')
2606+
frames.append(frame)
2607+
frames += reversed(frames[1:-1])
2608+
imageio.mimsave('test.gif', frames, duration=0.03)
2609+
```
2610+
25932611

25942612
Audio
25952613
-----

index.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,22 @@
22042204
<li><strong><code class="python hljs"><span class="hljs-string">'RGB'</span></code> - 3x8-bit pixels, true color.</strong></li>
22052205
<li><strong><code class="python hljs"><span class="hljs-string">'RGBA'</span></code> - 4x8-bit pixels, true color with transparency mask.</strong></li>
22062206
<li><strong><code class="python hljs"><span class="hljs-string">'HSV'</span></code> - 3x8-bit pixels, Hue, Saturation, Value color space.</strong></li>
2207-
</ul></div>
2207+
</ul><div><h3 id="animation">Animation</h3><div><h4 id="createsagifofabouncingball">Creates a GIF of a bouncing ball:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image, ImageDraw
2208+
<span class="hljs-keyword">import</span> imageio
2209+
height, r = <span class="hljs-number">126</span>, <span class="hljs-number">10</span>
2210+
frames = []
2211+
<span class="hljs-keyword">for</span> velocity <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>, <span class="hljs-number">16</span>):
2212+
y = sum(range(velocity))
2213+
frame = Image.new(<span class="hljs-string">'L'</span>, (height, height))
2214+
draw = ImageDraw.Draw(frame)
2215+
draw.ellipse((height/<span class="hljs-number">2</span>-r, y, height/<span class="hljs-number">2</span>+r, y+<span class="hljs-number">2</span>*r), fill=<span class="hljs-string">'white'</span>)
2216+
frames.append(frame)
2217+
frames += reversed(frames[<span class="hljs-number">1</span>:<span class="hljs-number">-1</span>])
2218+
imageio.mimsave(<span class="hljs-string">'test.gif'</span>, frames, duration=<span class="hljs-number">0.03</span>)
2219+
</code></pre></div></div></div>
2220+
2221+
2222+
22082223

22092224
<div><h2 id="audio"><a href="#audio" name="audio">#</a>Audio</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> wave
22102225
<span class="hljs-keyword">from</span> struct <span class="hljs-keyword">import</span> pack, iter_unpack

0 commit comments

Comments
 (0)