Last active
January 18, 2016 12:29
-
-
Save hoolrory/ffa68547966cca3bae59 to your computer and use it in GitHub Desktop.
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
# Python script to slice an image with a grid into equal sized pieces | |
# pip install Pillow | |
# | |
# Usage: | |
# python image_slicy.py IMAGE_PATH OUTPUT_FOLDER COLUMNS ROWS | |
import sys | |
from PIL import Image | |
image = sys.argv[1] | |
folder = sys.argv[2] | |
columns = int(sys.argv[3]) | |
rows = int(sys.argv[4]) | |
img = Image.open(image) | |
xSize = img.width / columns | |
ySize = img.height / rows | |
i = 0 | |
for c in range(0, columns): | |
for r in range(0, rows): | |
x = c * xSize | |
y = r * ySize | |
sub_image = img.crop((x, y, x + xSize, y + ySize)) | |
sub_image.save("{0}/img_{1}.png".format(folder, i)) | |
i+= 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment