Last active
August 29, 2015 14:21
-
-
Save alketii/07b9476edd8b9db76559 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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