Created
March 20, 2019 21:36
-
-
Save sbstp/c8e157ca5fafe660a37a50e65574e95c 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
from PIL import Image | |
WIDTH = 25 | |
HEIGHT = 25 | |
PAD_HEIGHT = 3 | |
PAD_WIDTH = 3 | |
source = Image.open("grid.png") | |
width, height = source.size | |
left = 0 | |
right = left + WIDTH | |
x = 1 | |
y = 1 | |
while left <= width: | |
top = 0 | |
bottom = top + HEIGHT | |
while top <= height: | |
sprite = source.crop((left, top, right, bottom)) | |
sprite.save("{:02}x{:02}.png".format(x, y)) | |
top += HEIGHT + PAD_HEIGHT | |
bottom = top + HEIGHT | |
y += 1 | |
left += WIDTH + PAD_WIDTH | |
right = left + WIDTH | |
x += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment