Created
February 25, 2017 05:24
-
-
Save aarqon/70952dc387a56216fc2e4af49934e860 to your computer and use it in GitHub Desktop.
Slices an image into uniform square tiles of a given size
This file contains hidden or 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
# Usage: python3 slicer.py [image] [size in pixels] | |
# Requires Pillow | |
import os | |
import sys | |
from PIL import Image | |
image_url = sys.argv[1] | |
size = int(sys.argv[2]) | |
print(image_url, size) | |
image = Image.open(image_url) | |
image_name = os.path.splitext(image_url)[0] | |
if not os.path.isdir(image_name): | |
os.mkdir(image_name) | |
for x in range(0,image.width,16): | |
for y in range(0,image.height,16): | |
tile = image.crop((x,y,(x+16),(y+16))) | |
tile.save(image_name+'/'+str(x)+'-'+str(y)+'.png') | |
tile.close() | |
image.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment