changeset 54 | 03e267d67478 |
53:57b4279d8c4e | 54:03e267d67478 |
---|---|
1 """ |
|
2 Utility functions for handling images. |
|
3 |
|
4 Requires PIL, as you might imagine. |
|
5 """ |
|
6 |
|
7 import ImageFile |
|
8 |
|
9 def get_image_dimensions(path): |
|
10 """Returns the (width, height) of an image at a given path.""" |
|
11 p = ImageFile.Parser() |
|
12 fp = open(path, 'rb') |
|
13 while 1: |
|
14 data = fp.read(1024) |
|
15 if not data: |
|
16 break |
|
17 p.feed(data) |
|
18 if p.image: |
|
19 return p.image.size |
|
20 break |
|
21 fp.close() |
|
22 return None |