I'm trying to figure out how to extract a given frame from an animated-gif, possibly in PIL, in Python. I'm not able to easily dig this up, and I'm guessing it would take some knowledge of the gif format, something that is not readily understandable to me. Is there any straightforward way to accomplish this? Do I need to do some custom parsing?
+2
A:
Reading Sequences
The GIF loader supports the
seek
andtell
methods. You can seek to the next frame(im.seek(im.tell()+1)
, or rewind the file by seeking to the first frame. Random access is not supported.
http://www.pythonware.com/library/pil/handbook/format-gif.htm http://www.pythonware.com/library/pil/handbook/image.htm
NullUserException
2010-08-14 05:50:53
Okay, how would I count the frames in the .gif?
CMC
2010-08-14 06:07:44
@CMC Apparently the only way is to keep seeking until an exception (`EOFError`) is raised.
NullUserException
2010-08-14 06:11:07
I guess that'll have to suffice. Thanks!
CMC
2010-08-14 06:13:56