Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'exception': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'trying': 0.19; '8bit%:5': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'issue.': 0.22; 'print': 0.22; 'install': 0.23; 'regardless': 0.24; 'extension': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; '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; 'called': 0.40; 'back': 0.62; 'more': 0.64; 'subject:check': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=MqM7/5/oEwdGSrk/FCpCgDbKLfWMy2SpVo+WKIe2WEI=; b=PXZJtNIXGcaJo/s2GRGfk/YEW3/dK3nQMOF8oNbXgi6iafEP6hx5VNEBr97bmr3TVo cxlA7qnhdaejke7A4Tkhf8pBwnw5+2wbmOGGzp52SPD4XAql5FwysDXjZNtFE8j5FfRy WcMhKbR1aSe6inFNFzqc5ibBeA9wuKYpPjFSSqA5H6QsOi/O4FELBIeAdnonto7nb+fK HTQnIxQyDbicurFcw8bwzAGCpRaWLm7DgCvZ5y+NtXhVjW5iYC4YOZMqY86K2c8dGlXF 955jeCT8k/fBg9m5j3MyEdiYrTgXckFlD/iePK4lOKEBJOo8BS60AF6YVFfigYb/p1pA vR6w== MIME-Version: 1.0 X-Received: by 10.180.37.109 with SMTP id x13mr24999020wij.20.1368087769956; Thu, 09 May 2013 01:22:49 -0700 (PDT) In-Reply-To: References: Date: Thu, 9 May 2013 09:22:49 +0100 Subject: Re: PIL: check if image is animated From: Sven To: python-list Content-Type: multipart/alternative; boundary=e89a8f6473f58ccaad04dc44c171 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 89 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368087777 news.xs4all.nl 15951 [2001:888:2000:d::a6]:34048 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45018 --e89a8f6473f58ccaad04dc44c171 Content-Type: text/plain; charset=ISO-8859-1 Figured out my issue. I did called the check_animated function more than once and the second call causes the exception unless I seek back to 0 On 6 May 2013 21:57, Sven wrote: > 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 --e89a8f6473f58ccaad04dc44c171 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Figured out my issue. I did called the check_animated func= tion more than once and the second call causes the exception unless I seek = back to 0


On 6 May 2013 21:57, Sven <svenito@gmail.com> wrote:
Hello,

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

I thought that this used to work:

f= rom PIL import Image


def check_anim= ated(img):
=A0 =A0 try:
=A0 =A0 =A0 =A0 img.seek(1= )
=A0 =A0 except (EOFError):
=A0 =A0 =A0 =A0 return 0
=A0 =A0 return 1

img =3D Image('image.jpg= 9;)
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 som= e 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 wit= hout PIL?

Python 2.7, linux

--
./Sven



--
./Sven --e89a8f6473f58ccaad04dc44c171--