getting size of gif

Premshree Pillai premshree_python at yahoo.co.in
Mon Mar 15 06:09:52 EST 2004


As long as you need only a particular image type
("gif"), this technique should be good, but of course
PIL has support for a large number of image formats,
and you should use it.

The problem I faced when using PIL (for the very same
purpose) was that when I conbert it into a Windows
executable (using py2exe), the number of dependencies
are huge. But if creating a Windows executable is of
no concern to you, then why bother? Use PIL.

-Premshree Pillai

 --- Fredrik Lundh <fredrik at pythonware.com> wrote: >
Garry Knight wrote:
> 
> > > 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!
> 
> 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 = 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.
> 
> 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.
> 
> </F>
> 
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list 

=====
-Premshree
[http://www.qiksearch.com/]

________________________________________________________________________
Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more. 
Go to: http://in.insurance.yahoo.com/licspecial/index.html




More information about the Python-list mailing list