Home > python > Get the size (dimension) of an image

Get the size (dimension) of an image

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

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

from PIL import Image  # uses pillow

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

Related
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’).

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: