Python: get size of image using PIL or Pillow

PIL Pillow

examples/python/pil_get_image_size.py

from PIL import Image
import sys

in_file = sys.argv[1]

img = Image.open(in_file)
print(img.size)
print(img.size[0])
print(img.size[1])

size returns a tuple of (width, height) of the image.

Related Pages

Python

Author

Gabor Szabo (szabgab)

Gabor Szabo, the author of the Python Maven web site.

Gabor Szabo