Ticket #11158: 11158.diff

File 11158.diff, 1.3 KB (added by Chris Beaven, 15 years ago)
  • django/core/files/images.py

    diff --git a/django/core/files/images.py b/django/core/files/images.py
    index 55008b5..ab9a398 100644
    a b class ImageFile(File):  
    2323        if not hasattr(self, '_dimensions_cache'):
    2424            close = self.closed
    2525            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)
    2927        return self._dimensions_cache
    3028
    31 def get_image_dimensions(file_or_path):
     29def get_image_dimensions(file_or_path, close=False):
    3230    """Returns the (width, height) of an image, given an open file or a path."""
    3331    # Try to import PIL in either of the two ways it can end up installed.
    3432    try:
    def get_image_dimensions(file_or_path):  
    3735        import ImageFile as PILImageFile
    3836       
    3937    p = PILImageFile.Parser()
    40     close = False
    4138    if hasattr(file_or_path, 'read'):
    4239        file = file_or_path
     40        file_pos = file.tell()
     41        file.seek(0)
    4342    else:
    4443        file = open(file_or_path, 'rb')
    4544        close = True
    def get_image_dimensions(file_or_path):  
    5554    finally:
    5655        if close:
    5756            file.close()
     57        else:
     58            file.seek(file_pos)
Back to Top