Snippet.Py: Getting an image resolution
August 03, 2009 at 21:49
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.
