Ticket #11158: patch.diff
File patch.diff, 938 bytes (added by , 15 years ago) |
---|
-
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 31 32 if hasattr(file_or_path, 'read'): 32 33 file = file_or_path 34 file_pos = file.tell() 35 file.seek(0) 36 we_opened_this_file = False 33 37 else: 34 38 file = open(file_or_path, 'rb') 39 we_opened_this_file = True 40 41 def file_cleanup(): 42 if we_opened_this_file: 43 file.close() 44 else: 45 file.seek(file_pos) 46 47 35 48 while 1: 36 49 data = file.read(1024) 37 50 if not data: 38 51 break 39 52 p.feed(data) 40 53 if p.image: 54 file_cleanup() 41 55 return p.image.size 56 57 file_cleanup() 42 58 return None