getting size of gif

Garry Knight garryknight at
Mon Mar 15 00:30:23 CET 2004

In message <mailman.13.1079302660.682.python-list at>, Fredrik Lundh

> note that you don't need all of PIL to run the above example; it's enough
> to install,,, and the
> * files you need for your application.  the binary
> extensions are not needed.

Gosh, what a payload! It might not be the Python way of doing things, but
this should work just as well:

f = open('x.gif', 'rb')
gif =         # 'gif89a'
width = ord( + 256 * ord(
depth = ord( + 256 * ord(
print "width = %d, depth = %d" % (width, depth)

You could just do in the second line if you're not worried about
checking that it's a valid gif file. Of course, this only works with
single-image files, not with animated gifs.

Garry Knight
garryknight at  ICQ 126351135
Linux registered user 182025

More information about the Python-list mailing list