Posts Tagged ‘content-length’

Get the size (dimension) of an image

April 4, 2011 Leave a comment

You want to get the size (dimension) of an image.

We will use the Pillow package here, which is the successor of PIL.

from PIL import Image  # uses pillow

image_file = "something.jpg"
im =
print im.size   # return value is a tuple, ex.: (1200, 800)

If the image is on the web and you don’t want to download it, you can get the size of the image in bytes (see this post and get ‘Content-Length’).