getting size of gif
garryknight at gmx.net
Mon Mar 15 00:30:23 CET 2004
In message <mailman.13.1079302660.682.python-list at python.org>, Fredrik Lundh
> note that you don't need all of PIL to run the above example; it's enough
> to install Image.py, ImageFile.py, ImagePalette.py, and the
> *ImagePlugin.py 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 = f.read(6) # 'gif89a'
width = ord(f.read(1)) + 256 * ord(f.read(1))
depth = ord(f.read(1)) + 256 * ord(f.read(1))
print "width = %d, depth = %d" % (width, depth)
You could just do f.seek(6) 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.
garryknight at gmx.net ICQ 126351135
Linux registered user 182025
More information about the Python-list