Please include code that reproduces the issue and whenever possible, an image that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.
The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as plone, Django, or buildout, try to replicate the issue just using Pillow.
code goes here
from PIL import Image
im = Image.open('test.gif')
For more information, see http://pillow.readthedocs.io/en/5.2.x/handbook/tutorial.html
def decode_gif_file(filename):
img = Image.open(filename)
try:
img.seek(1)
except EOFError:
print('Warning: it is a single frame GIF.')
return img, 1
return img, 2
# if multiframe
current_index = img.tell() + 1
img.seek(current_index)
# use ur frame with img below. loop current index and judge EOFError to get all frames.
hope it helps
@yo1995 Thanks, you're right, I didn't consider that the question might be about multiple frames
There is also ImageSequence - http://pillow.readthedocs.io/en/5.2.x/reference/ImageSequence.html
from PIL import Image, ImageSequence
im = Image.open("animation.gif")
index = 1
for frame in ImageSequence.Iterator(im):
frame.save("frame%d.png" % index)
index += 1
Feel free to comment if you have any further questions
Most helpful comment
For more information, see http://pillow.readthedocs.io/en/5.2.x/handbook/tutorial.html