2005-07-13 09:25:57 +08:00
|
|
|
"""
|
|
|
|
Utility functions for handling images.
|
|
|
|
|
|
|
|
Requires PIL, as you might imagine.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import ImageFile
|
|
|
|
|
|
|
|
def get_image_dimensions(path):
|
|
|
|
"""Returns the (width, height) of an image at a given path."""
|
|
|
|
p = ImageFile.Parser()
|
2005-07-26 06:16:30 +08:00
|
|
|
fp = open(path, 'rb')
|
2005-07-13 09:25:57 +08:00
|
|
|
while 1:
|
|
|
|
data = fp.read(1024)
|
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
p.feed(data)
|
|
|
|
if p.image:
|
|
|
|
return p.image.size
|
|
|
|
break
|
|
|
|
fp.close()
|
|
|
|
return None
|