mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 02:16:19 +03:00
Merge pull request #1833 from radarhere/docs
Changed documentation to refer to ImageSequence Iterator
This commit is contained in:
commit
8bacd05d5d
|
@ -400,26 +400,15 @@ Note that most drivers in the current version of the library only allow you to
|
||||||
seek to the next frame (as in the above example). To rewind the file, you may
|
seek to the next frame (as in the above example). To rewind the file, you may
|
||||||
have to reopen it.
|
have to reopen it.
|
||||||
|
|
||||||
The following iterator class lets you use the for-statement to loop over the
|
The following class lets you use the for-statement to loop over the sequence:
|
||||||
sequence:
|
|
||||||
|
|
||||||
A sequence iterator class
|
Using the ImageSequence Iterator class
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
class ImageSequence:
|
from PIL import ImageSequence
|
||||||
def __init__(self, im):
|
for frame in ImageSequence.Iterator(im):
|
||||||
self.im = im
|
|
||||||
def __getitem__(self, ix):
|
|
||||||
try:
|
|
||||||
if ix:
|
|
||||||
self.im.seek(ix)
|
|
||||||
return self.im
|
|
||||||
except EOFError:
|
|
||||||
raise IndexError # end of sequence
|
|
||||||
|
|
||||||
for frame in ImageSequence(im):
|
|
||||||
# ...do something to frame...
|
# ...do something to frame...
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user