Ticket #11158: patch.diff

File patch.diff, 938 bytes (added by kua, 15 years ago)

updated patch for this bug

  • images.py

     
    2828    """Returns the (width, height) of an image, given an open file or a path."""
    2929    from PIL import ImageFile as PILImageFile
    3030    p = PILImageFile.Parser()
     31
    3132    if hasattr(file_or_path, 'read'):
    3233        file = file_or_path
     34        file_pos = file.tell()
     35        file.seek(0)
     36        we_opened_this_file = False
    3337    else:
    3438        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
    3548    while 1:
    3649        data = file.read(1024)
    3750        if not data:
    3851            break
    3952        p.feed(data)
    4053        if p.image:
     54            file_cleanup()
    4155            return p.image.size
     56
     57    file_cleanup()
    4258    return None
Back to Top