old_contents: #!/usr/bin/python
  #
  # Determine the sizes of a bunch of images.
  #
  # Usage:
  # ./extract-sizes.py '*.jpg' > sizes.txt
  #
  # Produces a CSV file with three columns:
  # file-basename-no-extension,width,height
  
  import glob
  import os.path
  import re
  import subprocess
  import sys
  
  for pattern in sys.argv[1:]:
    for path in glob.glob(pattern):
      size_str = subprocess.check_output(['identify', path])
  
      m = re.search(r' (\d+)x(\d+) ', size_str)
      assert m, size_str
      width, height = [int(x) for x in m.groups()]
      assert width > 0
      assert height > 0
  
      base, _ = os.path.splitext(os.path.basename(path))
  
      print '%s,%d,%d' % (base, width, height)
  
new_contents: #!/usr/bin/python
  '''
  Determine the sizes of a bunch of images.
  
  Usage:
  ./extract-sizes.py '*.jpg' > sizes.txt
  
  Produces a CSV file with three columns:
  file-basename-no-extension,width,height
  '''
  
  import glob
  import os.path
  import sys
  from PIL import Image
  
  
  def image_size(path):
      image = Image.open(path)
      width, height = image.size
      return (width, height)
  
  if __name__ == '__main__':
      for pattern in sys.argv[1:]:
          for path in glob.glob(pattern):
              width, height = image_size(path)
              base, _ = os.path.splitext(os.path.basename(path))
              print('%s,%d,%d' % (base, width, height))
  
subject: use PIL for image