Almighty Bus Error

Blog about computer science, code snippets and tips.

GitHub repository with examples here.
Currently a Computer Engineering student at FCT/UNL.
August 3, 2009 at 9:49pm

Comments (View)

Snippet.Py: Getting an image resolution

Using PIL (Python Image Library) 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!"
    else:
        for name in argv:
            img = Image.open(name)
            print name + ": %d %d" % img.size

if __name__ == "__main__":
    main()

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