This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

pil slicing

By: a guest on Oct 8th, 2011  |  syntax: Python  |  size: 0.41 KB  |  views: 72  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import os
  2. from PIL import Image
  3. imdir = "directory of images"
  4. savedir="path to where you wanna save the files"
  5. files = [os.path.join(imdir, fname) for fname in os.lsdir(imdir)]
  6. for infile in files:
  7.     im = pil.Image.open(infile)
  8.     file, ext = os.path.splitext(infile)
  9.     //first region
  10.     slice1 = im.crop((left, upper, right, lower)
  11.     slice.save(file+"slice1", "JPEG")
  12.    //copy and paste with new boxes
  13.  
clone this paste RAW Paste Data