Ticket #8817: 8817.diff
File 8817.diff, 1.2 KB (added by , 16 years ago) |
---|
-
django/core/files/images.py
28 28 """Returns the (width, height) of an image, given an open file or a path.""" 29 29 from PIL import ImageFile as PILImageFile 30 30 p = PILImageFile.Parser() 31 if hasattr(file_or_path, 'read'): 31 needs_close = True 32 # If we have a file name, prefer to open a new file to avoid modifying the 33 # state of the file object we were given. 34 if hasattr(file_or_path, 'name'): 35 # If this is a FileField, use custom storage backend to re-open file 36 if hasattr(file_or_path, 'storage'): 37 file = file_or_path.storage.open(file_or_path.name, 'rb') 38 else: 39 file = open(file_or_path.name, 'rb') 40 elif hasattr(file_or_path, 'read'): 32 41 file = file_or_path 42 needs_close = False 33 43 else: 34 44 file = open(file_or_path, 'rb') 35 45 while 1: … … 38 48 break 39 49 p.feed(data) 40 50 if p.image: 51 if needs_close: 52 file.close() 41 53 return p.image.size 54 if needs_close: 55 file.close() 42 56 return None