Skip to content

Instantly share code, notes, and snippets.

@alketii
Last active August 29, 2015 14:21
Show Gist options
  • Save alketii/07b9476edd8b9db76559 to your computer and use it in GitHub Desktop.
Save alketii/07b9476edd8b9db76559 to your computer and use it in GitHub Desktop.
"""
To run this on ubuntu, first do
sudo apt-get install python-pil python-easygui
note: pil can also be python-pillow
"""
import os
import easygui as eg
from PIL import Image
image_file = eg.fileopenbox("Select Image")
image=Image.open(image_file)
file_dir = os.path.dirname(image_file)
file_name = os.path.splitext(os.path.basename(image_file))[0]
tile_width = int(eg.enterbox("Tile Width in PX"))
tile_height = int(eg.enterbox("Tile Height in PX"))
tiles_x = image.size[0]/tile_width
tiles_y = image.size[1]/tile_height
count = 0
for y in range(tiles_y):
for x in range(tiles_x):
count += 1
image.crop((x*tile_width,y*tile_height,x*tile_width+tile_width,y*tile_height+tile_height)).save(file_dir+"/"+file_name+"_tile_"+str(count)+".png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment