PIL: check if image is animated

Discussion in 'Python' started by Sven, May 6, 2013.

  1. Sven

    Sven Guest

    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

    --
    ../Sven
     
    Sven, May 6, 2013
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.verizon.net

    Animated GIF not working...Please Check

    news.verizon.net, Feb 1, 2004, in forum: HTML
    Replies:
    4
    Views:
    3,502
    Leif K-Brooks
    Feb 1, 2004
  2. Daniel Mark
    Replies:
    1
    Views:
    784
    Fredrik Lundh
    Sep 25, 2006
  3. Andrew
    Replies:
    0
    Views:
    566
    Andrew
    Apr 5, 2007
  4. Sverre
    Replies:
    2
    Views:
    3,683
    Sverre
    Dec 17, 2009
  5. Sven
    Replies:
    0
    Views:
    103
Loading...

Share This Page