File: images.py

package info (click to toggle)
python-django 0.95.1-1etch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 6,344 kB
  • ctags: 3,919
  • sloc: python: 24,083; makefile: 14; sql: 6
file content (22 lines) | stat: -rw-r--r-- 458 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
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()
    fp = open(path, 'rb')
    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