getting size of gif

Fredrik Lundh fredrik at
Mon Mar 15 09:25:19 CET 2004

Garry Knight wrote:

> > 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!

you can download the files from the net; you don't have to type
them in yourself.

> 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.

it gives you the height, not the depth.  and it returns the size of
the logical screen, so it should work with animated GIFs as well.

but it doesn't give you any other information about the file, and it
doesn't work for JPEGs, PNG files, or any of the other 35+ formats
PIL supports.


More information about the Python-list mailing list