Tim Hatch

Weblog | Photos | Projects | Panoramas | About

pyimagesize

I started writing this module when I was writing an image gallery script in Python. It's so easy in certain other languages (ahem, php) to get the image dimensions by just parsing the headers, but in Python you need to use PIL or call an external script. Rather than do that, I decided to just write my own since it's code I'd really rather reuse.

Note: If you're not using Python already and you just want the dimensions, use the identify script from ImageMagick.

The jpeg parser is loosely based on some code from the Python mailing list but the rest were reverse engineered using documentation available on the 'Net.

Downloads

Latest stable verison is pyimagesize-0.1.tbz2 (asc), or browse the distribution directory for older versions.

The development source is accessible via bzr branch http://code.timhatch.com/bzr/pyimagesize/

Example Usage

from imagesize import get_info

o = get_info("temp.png")
print o.width, o.height

Docs

See docs or the docs/src in the distribution.

Contributing

I welcome patches, suggestions, and bugreports. Send me an email to code@timhatch.com