All pastes #950 Raw Edit

Anonymous

public python v1 · immutable
#950 ·published 2004-09-15 22:16 UTC
rendered paste body
#!/usr/bin/env python"""Print the dimension(s) of the image(s) passed on the command line.  Either canbe run on files or on local files."""import osimport urllibimport ImageFiledef getsizes(uri):    # kill the << warnings from PIL...    import warnings    warnings.filterwarnings("ignore", "x<<y")        if uri.startswith("http://"):        file = urllib.urlopen(uri)    else:        file = open(uri)            p = ImageFile.Parser()    while 1:        data = file.read(1024)        if not data:            break        p.feed(data)        if p.image:            return p.image.size            break    file.close()    return Noneif __name__ == '__main__':    import sys    for uri in sys.argv[1:]:        size = getsizes(uri)        if not size:            size = 'Invalid or nonexistant URI'        print "%s: %s" % (os.path.basename(uri), size)