Skip to content

Instantly share code, notes, and snippets.

@matiskay
Created November 18, 2012 03:18
Show Gist options
  • Save matiskay/4103283 to your computer and use it in GitHub Desktop.
Save matiskay/4103283 to your computer and use it in GitHub Desktop.
Get width and height from an image file
#! /usr/bin/python
from PIL import Image
import sys
if len(sys.argv) >= 2:
image_file = sys.argv[1]
try:
img = Image.open(image_file)
width, height = img.size
sys.stdout.write('width: {0}px; height: {1}px;'.format(width, height))
sys.stdout.write('\n')
except IOError:
sys.stderr.write('The file is not an image')
sys.stderr.write('\n')
else:
sys.stderr.write('Add a parameter')
sys.stderr.write('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment