Skip to content

Instantly share code, notes, and snippets.

@badjano
Created November 23, 2018 00:53
Show Gist options
  • Save badjano/7654a8c65a188ed5b8041252e5171a0b to your computer and use it in GitHub Desktop.
Save badjano/7654a8c65a188ed5b8041252e5171a0b to your computer and use it in GitHub Desktop.
Sprite Sheet Patcher
from math import floor
from PIL import Image
def make_sprite_sheet(folder):
files = ["%s/bkfire%04d.png" % (folder, a) for a in range(1, 65)]
images = [Image.open(a) for a in files]
width, height = images[0].size
sides = int(pow(len(images), 0.5))
total_width = width * sides
max_height = height * sides
new_im = Image.new('RGBA', (total_width, max_height))
for i in range(len(images)):
img = images[i]
x = (i % sides) * width
y = floor(i / sides) * height
new_im.paste(img, (x, y))
new_im.resize((1024, 1024)).save('%s.png' % folder)
make_sprite_sheet("BKFire")
# make_sprite_sheet("BKFireSmoke")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment