From d031b2107ae1aba258b7f6d5ae3163805a838975 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Fri, 21 May 2021 21:47:26 +0000 Subject: [PATCH] Pad out written PNG frames so all of them have the same number of digits in them. --- bemani/utils/afputils.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bemani/utils/afputils.py b/bemani/utils/afputils.py index 2a05fd4..2278419 100644 --- a/bemani/utils/afputils.py +++ b/bemani/utils/afputils.py @@ -2,6 +2,7 @@ import argparse import io import json +import math import os import os.path import sys @@ -800,13 +801,18 @@ def main() -> int: filename = args.output[:-4] ext = args.output[-4:] - for i, img in enumerate(images): - fullname = f"{filename}-{i}{ext}" + # Figure out padding for the images. + frames = len(images) + if frames > 0: + digits = f"0{int(math.log10(frames)) + 1}" - with open(fullname, "wb") as bfp: - img.save(bfp, format=fmt) + for i, img in enumerate(images): + fullname = f"{filename}-{i:{digits}}{ext}" - print(f"Wrote animation frame to {fullname}") + with open(fullname, "wb") as bfp: + img.save(bfp, format=fmt) + + print(f"Wrote animation frame to {fullname}") elif args.action == "list": paths = renderer.list_paths(verbose=args.verbose)