Skip to content

Instantly share code, notes, and snippets.

@AnBucquet
Created January 17, 2019 10:26
Show Gist options
  • Select an option

  • Save AnBucquet/f61e1b5feb6fd8f5202cb1eb365146d1 to your computer and use it in GitHub Desktop.

Select an option

Save AnBucquet/f61e1b5feb6fd8f5202cb1eb365146d1 to your computer and use it in GitHub Desktop.
A little function to split an image into many and save them into a specific directory.
from PIL import Image
def split(path, input, height, width):
im = Image.open(input)
k = 0
imgwidth, imgheight = im.size
for i in range(0,imgheight,height):
for j in range(0,imgwidth,width):
box = (j, i, j+width, i+height)
a = im.crop(box)
try:
a.save(path+"VanGogh_fake_{}".format(k)+'.jpg')
except:
pass
k +=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment