Merge pull request #9 from Pichok/generate_thumbnails_of_large_movies

Generate Thumbnails of large movies
This commit is contained in:
Flávio Ribeiro
2017-01-06 11:54:52 -05:00
committed by GitHub

View File

@@ -59,22 +59,27 @@ def resize_frame(filename, size):
def generate_sprite_from_frames(framesPath, columns, size, output): def generate_sprite_from_frames(framesPath, columns, size, output):
framesMap = sorted(glob.glob(framesPath + "*.png")) 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 line, column = 0, 0
for image in images:
locationX = size[0] * column finalImage = Image.new(mode='RGBA', size=(masterWidth, masterHeight), color=(0,0,0,0))
locationY = size[1] * line
finalImage.paste(image, (locationX, locationY)) for filename in framesMap:
column += 1 with Image.open(filename) as image:
if column == columns:
line += 1 locationX = size[0] * column
column = 0 locationY = size[1] * line
finalImage.paste(image, (locationX, locationY))
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)