To read a multi-frame image file in Python Imaging Library (PIL), we use the ‘ImageSequence’ module. First, open the image using ‘Image.open()’. Then, create an iterator with ‘ImageSequence.Iterator(image)’. This iterator can be used to loop through each frame of the image. For example:
from PIL import Image, ImageSequence
image = Image.open('animated_image.gif')
for i, frame in enumerate(ImageSequence.Iterator(image)):
frame.save("frame%d.png" % i)
This code opens an animated GIF and saves each frame as a separate PNG file.