bugfix on the position of the frames

This commit is contained in:
Flávio Ribeiro
2015-11-18 01:24:10 -05:00
parent c770b03d4a
commit 30646ec236

View File

@@ -60,19 +60,21 @@ def resize_image(filename, size):
def generate_sprite_from_images(framesPath, columns, size, output): def generate_sprite_from_images(framesPath, columns, size, output):
framesMap = sorted(glob.glob(framesPath + "*.png")) framesMap = sorted(glob.glob(framesPath + "*.png"))
images = [Image.open(filename) for filename in framesMap] images = [Image.open(filename) for filename in framesMap]
print "%d frames will be combined." % len(images)
masterWidth = size[0] * columns masterWidth = size[0] * columns
masterHeight = size[1] * int(math.ceil(float(len(images)) / columns)) masterHeight = size[1] * int(math.ceil(float(len(images)) / columns))
finalImage = Image.new(mode='RGBA', size=(masterWidth, masterHeight), color=(0,0,0,0)) finalImage = Image.new(mode='RGBA', size=(masterWidth, masterHeight), color=(0,0,0,0))
merge_frames(images, finalImage, columns, size, output) merge_frames(images, finalImage, columns, size, output)
def merge_frames(images, finalImage, columns, size, output): def merge_frames(images, finalImage, columns, size, output):
line = 0 line, column = 0, 0
for i, image in enumerate(images): for image in images:
locationX = size[0] * i locationX = size[0] * column
locationY = size[1] * line locationY = size[1] * line
finalImage.paste(image, (locationX, locationY)) 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) finalImage.save(output, transparency=0)
shutil.rmtree(TMP_FRAMES_PATH, ignore_errors=True) shutil.rmtree(TMP_FRAMES_PATH, ignore_errors=True)