Skip to content

Instantly share code, notes, and snippets.

@kndt84
Last active June 18, 2018 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kndt84/fa7eb9bcd44abec2832a18547db8e3d6 to your computer and use it in GitHub Desktop.
Save kndt84/fa7eb9bcd44abec2832a18547db8e3d6 to your computer and use it in GitHub Desktop.
import os
import glob
from PIL import Image, ImageOps
path_list = glob.glob('*.png')
for path in path_list:
filename, ext = os.path.splitext( os.path.basename(path) )
im = Image.open(path)
width, height = im.size
x1= (width-height)/2
y1=0
x2=(width-height)/2+height
y2=height
im2 = im.crop((x1,y1,x2,y2)).resize((256,256))
im2.save('%s-crop%s' % (filename, ext))
im2.rotate(90).save('%s-r90%s' % (filename, ext))
im2.rotate(180).save('%s-r180%s' % (filename, ext))
im2.rotate(270).save('%s-r270%s' % (filename, ext))
ImageOps.flip(im2).save('%s-flip%s' % (filename, ext))
ImageOps.mirror(im2).save('%s-mirror%s' % (filename, ext))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment