mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-26 16:50:33 +03:00
Add tutorial images
Animated gif example
This commit is contained in:
parent
18d8020cab
commit
96a1af9fa8
BIN
docs/handbook/animated_hopper.gif
Normal file
BIN
docs/handbook/animated_hopper.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
|
@ -511,10 +511,43 @@ Reading sequences
|
|||
As seen in this example, you’ll get an :py:exc:`EOFError` exception when the
|
||||
sequence ends.
|
||||
|
||||
Writing sequences
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
You can create animated GIFs with Pillow, e.g.
|
||||
|
||||
::
|
||||
|
||||
from PIL import Image
|
||||
|
||||
# List of image filenames
|
||||
image_filenames = [
|
||||
"hopper.jpg",
|
||||
"rotated_hopper_270.jpg",
|
||||
"rotated_hopper_180.jpg",
|
||||
"rotated_hopper_90.jpg",
|
||||
]
|
||||
|
||||
# Open images and append them to a list
|
||||
images = [Image.open(filename) for filename in image_filenames]
|
||||
|
||||
# Save the images as an animated GIF
|
||||
images[0].save(
|
||||
"animated_hopper.gif",
|
||||
save_all=True,
|
||||
append_images=images[1:],
|
||||
duration=500, # duration of each frame in milliseconds
|
||||
loop=0, # loop forever
|
||||
)
|
||||
|
||||
|
||||
.. image:: animated_hopper.gif
|
||||
:align: center
|
||||
|
||||
The following class lets you use the for-statement to loop over the sequence:
|
||||
|
||||
Using the ImageSequence Iterator class
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Using the :py:meth:`ImageSequence.Iterator` class
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
::
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user