bugfix on the position of the frames
This commit is contained in:
12
generator
12
generator
@@ -60,19 +60,21 @@ def resize_image(filename, size):
|
||||
def generate_sprite_from_images(framesPath, columns, size, output):
|
||||
framesMap = sorted(glob.glob(framesPath + "*.png"))
|
||||
images = [Image.open(filename) for filename in framesMap]
|
||||
print "%d frames will be combined." % len(images)
|
||||
masterWidth = size[0] * columns
|
||||
masterHeight = size[1] * int(math.ceil(float(len(images)) / columns))
|
||||
finalImage = Image.new(mode='RGBA', size=(masterWidth, masterHeight), color=(0,0,0,0))
|
||||
merge_frames(images, finalImage, columns, size, output)
|
||||
|
||||
def merge_frames(images, finalImage, columns, size, output):
|
||||
line = 0
|
||||
for i, image in enumerate(images):
|
||||
locationX = size[0] * i
|
||||
line, column = 0, 0
|
||||
for image in images:
|
||||
locationX = size[0] * column
|
||||
locationY = size[1] * line
|
||||
finalImage.paste(image, (locationX, locationY))
|
||||
if i != 0 and i % columns == 0: line += 1
|
||||
column += 1
|
||||
if column == columns:
|
||||
line += 1
|
||||
column = 0
|
||||
|
||||
finalImage.save(output, transparency=0)
|
||||
shutil.rmtree(TMP_FRAMES_PATH, ignore_errors=True)
|
||||
|
||||
Reference in New Issue
Block a user