Almighty Bus Error

Blog about computer science, code snippets and tips.

GitHub repository with examples.
The author is a Computer Engineering student at FCT/UNL.
rss
August 03, 2009 at 21:49

Comments (View)

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!"
    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 github.

[top]

[top]