From 30f05b0656547a1093ae6a402c337366051c782e Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Mon, 13 Nov 2023 17:59:59 +1100 Subject: [PATCH] thumbnails: Add a CLI for generating them directly --- common/common/images.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/common/images.py b/common/common/images.py index 8825ded..0cd9eb2 100644 --- a/common/common/images.py +++ b/common/common/images.py @@ -1,6 +1,7 @@ import json import os +import sys from io import BytesIO from PIL import Image @@ -70,3 +71,15 @@ def compose_thumbnail_template(base_dir, template_name, frame_data): result.save(buf, format='png') buf.seek(0) return buf.read() + + +def cli(template_name, image, base_dir="."): + with open(image, "rb") as f: + image = f.read() + thumbnail = compose_thumbnail_template(base_dir, template_name, image) + sys.stdout.buffer.write(thumbnail) + + +if __name__ == '__main__': + import argh + argh.dispatch_command(cli)