Skip to content

Instantly share code, notes, and snippets.

@sbstp
Created March 20, 2019 21:36
Show Gist options
  • Save sbstp/c8e157ca5fafe660a37a50e65574e95c to your computer and use it in GitHub Desktop.
Save sbstp/c8e157ca5fafe660a37a50e65574e95c to your computer and use it in GitHub Desktop.
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