Skip to content

Instantly share code, notes, and snippets.

@zhuth
Last active August 29, 2015 14:04
Show Gist options
  • Save zhuth/49259c347b83bbcbc007 to your computer and use it in GitHub Desktop.
Save zhuth/49259c347b83bbcbc007 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
from PIL import Image
fmt = '.tiff'
bias = 0
p = './'
a = os.listdir(p)
for i in a:
path = p+'crop/'+i
if i[-len(fmt):] != fmt:
continue
print path
f = Image.open(i).convert('1')
xsize,ysize=f.size
xsize-=bias
box=(bias,0,bias+xsize/2,ysize)
f.crop(box).save(path + '_1' + fmt)
box=(bias+xsize/2,0,bias+xsize,ysize)
f.crop(box).save(path + '_2' + fmt)
#box=(20,150,xsize-240,ysize-150)
#f.crop(box).save(path + '_1' + fmt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment