-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite_sheet_generator_script.py
51 lines (30 loc) · 1.04 KB
/
sprite_sheet_generator_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
Script générant la spritesheet
utilisable tel quel
possible déclinaison en CLI
'''
from PIL import Image
from pathlib import Path
import math
URL = ""
NUMBER_OF_COLUMNS = 6
images_path = Path(URL)
list_img = list(images_path.glob('*png'))
SIZE_IMAGE = ()
sprite_image = None
for index, image in enumerate(list_img):
number_of_rows = math.ceil(len(list_img) / NUMBER_OF_COLUMNS)
img = Image.open(image)
if(SIZE_IMAGE != img.size):
# Initialisation de l'image de la sprite
sprite_image = Image.new('RGBA', (img.width * NUMBER_OF_COLUMNS, img.height* number_of_rows))
# si l'index n'est pas égal à zéro et que l'image est différentes alors
if(index != 0):
print(f"{image.name} is not the same size as previous image")
break # fin de la boucle
SIZE_IMAGE = img.size
posX = (index % NUMBER_OF_COLUMNS) * img.width
posY = math.floor( index / NUMBER_OF_COLUMNS ) * img.height
print(posX, posY)
sprite_image.paste(img, (posX, posY))
sprite_image.show()