PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageSequence module contains a wrapper class that lets you iterate over the frames of an image sequence.
ImageSequence.Iterator() This class implements an iterator object that can be used to loop over an image sequence. You can use the [ ] operator to access elements by index. This operator will raise an IndexError if you try to access a nonexistent frame.
Syntax: PIL.ImageSequence.Iterator(im)
Parameters:
im – An image object.Returns: An Image object.
Image Used:

# importing Image class from PIL package from PIL import Image, ImageSequence # creating a object im = Image.open(r"C:\Users\System-Pc\Desktop\home.png") index = 1for frame in ImageSequence.Iterator(im): frame.save("frame % d.png" % index) index = index + 1 im.getdata() im.show() |
Output:

Another Example:Here we use another image .jpg extension.
Image Used:

# importing Image class from PIL package from PIL import Image, ImageSequence # creating a object im = Image.open(r"C:\Users\System-Pc\Desktop\tree.jpg") index = 1for frame in ImageSequence.Iterator(im): frame.save("frame % d.jpg" % index) index = index + 1 im.getdata() im.show() |
Output:

Recommended Posts:
- Python PIL | GaussianBlur() method
- Python PIL | ImageDraw.Draw.pieslice()
- Python PIL | Kernel() method
- Python PIL | BoxBlur() method
- Python PIL | getbands() method
- Python PIL | logical_and() and logical_or() method
- Python PIL | ImageChops.subtract() method
- Python PIL | UnsahrpMask() method
- Python PIL | ImageChops.subtract() and ImageChops.subtract_modulo() method
- Python PIL | Image.crop() method
- Python PIL | ImageOps.expand() method
- Python PIL | ImageEnhance.Color() and ImageEnhance.Contrast() method
- Python PIL | ImageGrab.grabclipboard() method
- Python PIL | RankFilter() method
- Python PIL | ImageChops.screen() and ImageChops.offset() method
- Python PIL | MedianFilter() and ModeFilter() method
- Python PIL | Image.new() method
- Python PIL | getbands() and getextrema() method
- Python PIL | paste() and rotate() method
- Python PIL | ImageChops.darker() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

