Almighty Bus Error

Loading search...

Snippet.Py: Getting an image resolution

Using PIL it is possible to get the width and height of a image using the property size.

The following example will take an undefined number of arguments and print all the resolutions:

import Image
import sys
def main():
    argv = sys.argv[1:]
    if (len(argv) == 0):
        print "No file given!"
        for name in argv:
            img =
            print name + ": %d %d" % img.size
if __name__ == "__main__":

Credit for the snippet goes to meqif.
The code can also be found at github.