diff --git a/django/core/files/images.py b/django/core/files/images.py
index 55008b5..ab9a398 100644
a
|
b
|
class ImageFile(File):
|
23 | 23 | if not hasattr(self, '_dimensions_cache'): |
24 | 24 | close = self.closed |
25 | 25 | self.open() |
26 | | self._dimensions_cache = get_image_dimensions(self) |
27 | | if close: |
28 | | self.close() |
| 26 | self._dimensions_cache = get_image_dimensions(self, close=close) |
29 | 27 | return self._dimensions_cache |
30 | 28 | |
31 | | def get_image_dimensions(file_or_path): |
| 29 | def get_image_dimensions(file_or_path, close=False): |
32 | 30 | """Returns the (width, height) of an image, given an open file or a path.""" |
33 | 31 | # Try to import PIL in either of the two ways it can end up installed. |
34 | 32 | try: |
… |
… |
def get_image_dimensions(file_or_path):
|
37 | 35 | import ImageFile as PILImageFile |
38 | 36 | |
39 | 37 | p = PILImageFile.Parser() |
40 | | close = False |
41 | 38 | if hasattr(file_or_path, 'read'): |
42 | 39 | file = file_or_path |
| 40 | file_pos = file.tell() |
| 41 | file.seek(0) |
43 | 42 | else: |
44 | 43 | file = open(file_or_path, 'rb') |
45 | 44 | close = True |
… |
… |
def get_image_dimensions(file_or_path):
|
55 | 54 | finally: |
56 | 55 | if close: |
57 | 56 | file.close() |
| 57 | else: |
| 58 | file.seek(file_pos) |