From 1897d40707f4ae679ee7c1f69eed600ec2173bc1 Mon Sep 17 00:00:00 2001 From: Guilherme Pichok Date: Wed, 4 Jan 2017 01:09:10 -0200 Subject: [PATCH] Generate Thumbnails of large movies --- generator | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/generator b/generator index 1d8700f..c99abea 100755 --- a/generator +++ b/generator @@ -59,22 +59,27 @@ def resize_frame(filename, size): def generate_sprite_from_frames(framesPath, columns, size, output): framesMap = sorted(glob.glob(framesPath + "*.png")) - images = [Image.open(filename) for filename in framesMap] - 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): + masterWidth = size[0] * columns + masterHeight = size[1] * int(math.ceil(float(len(framesMap)) / columns)) + line, column = 0, 0 - for image in images: - locationX = size[0] * column - locationY = size[1] * line - finalImage.paste(image, (locationX, locationY)) - column += 1 - if column == columns: - line += 1 - column = 0 + + finalImage = Image.new(mode='RGBA', size=(masterWidth, masterHeight), color=(0,0,0,0)) + + for filename in framesMap: + with Image.open(filename) as image: + + locationX = size[0] * column + locationY = size[1] * line + + finalImage.paste(image, (locationX, locationY)) + + column += 1 + + if column == columns: + line += 1 + column = 0 finalImage.save(output, transparency=0) shutil.rmtree(TMP_FRAMES_PATH, ignore_errors=True)