From 3c1f996342ab02e15a9583bbb04fa1261d476c83 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Sat, 18 Nov 2023 15:57:36 +0800 Subject: [PATCH] Update log messages and set a more dynamic image resize up to a limit --- scripts/resize-img | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/resize-img b/scripts/resize-img index 0c1bcb4..f0ad63d 100755 --- a/scripts/resize-img +++ b/scripts/resize-img @@ -4,15 +4,13 @@ import sys def main(): - target_width = 2048 - argn = len(sys.argv) if argn == 1: - print("You must specify an input file") + print("Error: You must specify an input file") exit(1) elif argn == 2: - print("You must specify an output file") + print("Error: You must specify an output file") exit(1) input_image_path = sys.argv[1] @@ -21,10 +19,12 @@ def main(): try: image = Image.open(input_image_path) except IOError: - print(f"Cannot open image file {input_image_path}") + print(f"Error: Cannot open image file {input_image_path}") + image.close() exit(1) width, height = image.size + target_width = int(max(width/4, 1280)) new_height = int(target_width * height / width) image = image.resize((target_width, new_height), Image.Resampling.BICUBIC) @@ -37,7 +37,8 @@ def main(): try: image.save(output_image_path, **kwargs) except IOError: - print(f"Cannot save file {output_image_path}") + print(f"Error: Cannot save file {output_image_path}") + image.close() exit(1)