1
0
mirror of synced 2025-02-02 04:17:54 +01:00
jujube/utils/spritesheet_maker.py

26 lines
757 B
Python
Raw Normal View History

from math import sqrt, ceil
from PIL import Image
from path import Path
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("files", type=Path, nargs="+")
2020-05-23 00:04:13 +02:00
parser.add_argument("--columns", type=int)
args = parser.parse_args()
images = [Image.open(file) for file in args.files]
assert len(set(image.size for image in images)) == 1
sprite_size = images[0].size
2020-05-23 00:04:13 +02:00
columns = args.columns or ceil(sqrt(len(images)))
rows = len(images) // columns
width = columns * sprite_size[0]
height = rows * sprite_size[1]
sheet = Image.new('RGBA', (width, height), (0,0,0,0))
for index, sprite in enumerate(images):
2020-05-23 00:04:13 +02:00
x = (index % columns)*sprite_size[0]
y = (index // columns)*sprite_size[1]
sheet.paste(sprite, (x,y))
sheet.save("sheet.png")