PIL: check if image is animated

S

Sven

Hello,

I am trying to check if an image is animated. I can't rely on the extension
as it may be a gif that's been renamed to .jpg or something else and is
still animated.

I thought that this used to work:

from PIL import Image


def check_animated(img):
try:
img.seek(1)
except (EOFError):
return 0
return 1

img = Image('image.jpg')
print "animated?", check_animated(img)

Regardless if it's animated or not I get this exception:
ValueError: cannot seek to frame 1

I need to return 0 or 1, so excuse not using True or False.

Did the above get deprecated/change in a version at some point? Perhaps
there's something I missed during install (using PIP). Are there any other
ways to accomplish what I am trying to do, with or without PIL?

Python 2.7, linux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top