Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44851

PIL: check if image is animated

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <svenito@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(using': 0.07; 'false.': 0.09; 'pil': 0.09; 'pil?': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'python': 0.11; 'def': 0.12; 'missed': 0.12; 'exception:': 0.16; 'renamed': 0.16; 'subject:PIL': 0.16; 'subject:image': 0.16; 'do,': 0.16; 'trying': 0.19; '8bit%:5': 0.22; 'import': 0.22; 'print': 0.22; 'install': 0.23; 'regardless': 0.24; 'extension': 0.26; 'message-id:@mail.gmail.com': 0.30; 'img': 0.31; 'work:': 0.31; 'linux': 0.33; 'to:name:python-list': 0.33; "can't": 0.35; 'except': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'to:addr:python-list': 0.38; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'subject:check': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=ybOoWqq6LzwcsnBUM1O2SyRxuNXVG8mVo/yFRF2iBGY=; b=E0222Bb/rcemvJZV852lBJaiJHtI9gZHz0nMOSoJkGLC9inO8NhQJZpaUDvnd+2w+a ffPd8RG6WMS1V3luMoACu/IE6tWemSOmKjEfhI9kpHaQIcdPClX9Mb4uD1lVW8OaRYte 1oCbZCLlJLPBITuDI/ggIhvTaE8oJe5nFXRIZTO+Xo+6nbIDVLjLF83M93zsMWTaJJHk d/6+18lYhkGQRJriF76sEyuanYX9r+7//Q2i1u+3qoM0cEuhrtTv5/bktiAC8oWPoj23 7EIpNHC61wTkrk1P4ESF3r9W53G2hwYErig7iRZ5qXN51d9fmQsQ5fItHS7QUkJp0QhT Ilew==
MIME-Version 1.0
X-Received by 10.194.62.18 with SMTP id u18mr27233194wjr.53.1367873821780; Mon, 06 May 2013 13:57:01 -0700 (PDT)
Date Mon, 6 May 2013 21:57:01 +0100
Subject PIL: check if image is animated
From Sven <svenito@gmail.com>
To python-list <python-list@python.org>
Content-Type multipart/alternative; boundary=047d7ba97cdc3eb1af04dc12f1a6
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1385.1367873828.3114.python-list@python.org> (permalink)
Lines 66
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1367873828 news.xs4all.nl 15971 [2001:888:2000:d::a6]:44382
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44851

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

PIL: check if image is animated Sven <svenito@gmail.com> - 2013-05-06 21:57 +0100

csiph-web