Index: images.py
===================================================================
--- images.py	(revision 11109)
+++ images.py	(working copy)
@@ -28,15 +28,31 @@
     """Returns the (width, height) of an image, given an open file or a path."""
     from PIL import ImageFile as PILImageFile
     p = PILImageFile.Parser()
+
     if hasattr(file_or_path, 'read'):
         file = file_or_path
+        file_pos = file.tell()
+        file.seek(0)
+        we_opened_this_file = False
     else:
         file = open(file_or_path, 'rb')
+        we_opened_this_file = True
+
+    def file_cleanup():
+        if we_opened_this_file:
+          file.close()
+        else:
+          file.seek(file_pos)
+
+
     while 1:
         data = file.read(1024)
         if not data:
             break
         p.feed(data)
         if p.image:
+            file_cleanup()
             return p.image.size
+
+    file_cleanup()
     return None
