Compare commits

...

2 Commits

Author SHA1 Message Date
sheldonmlee c5b4dda950 Detect errors from resize-img using substr_count() 2023-11-18 16:42:33 +08:00
sheldonmlee 22a70bd4de Refactor resize-img error printing 2023-11-18 16:41:32 +08:00
2 changed files with 10 additions and 6 deletions
+2 -1
View File
@@ -86,8 +86,9 @@ function create_thumbnail(string $category, string $file): string | null {
log_print("generating thumbnail for $original_file");
$output = shell_exec(THUMBNAIL_SCRIPT." '$original_file' '$thumbnail_file' 2>&1");
if ($output) log_print($output);
if ($output === false) {
if (substr_count(strtolower((string) $output), "error")) {
log_error("Thumbnail failed");
log_print(ROOT_URL.IMG_DIR.$path);
return ROOT_URL.IMG_DIR.$path;
}
+8 -5
View File
@@ -5,12 +5,11 @@ import sys
def main():
argn = len(sys.argv)
if argn == 1:
print("Error: You must specify an input file")
print_error("You must specify an input file")
exit(1)
elif argn == 2:
print("Error: You must specify an output file")
print_error("You must specify an output file")
exit(1)
input_image_path = sys.argv[1]
@@ -19,7 +18,7 @@ def main():
try:
image = Image.open(input_image_path)
except IOError:
print(f"Error: Cannot open image file {input_image_path}")
print_error(f"Cannot open image file {input_image_path}")
image.close()
exit(1)
@@ -37,11 +36,15 @@ def main():
try:
image.save(output_image_path, **kwargs)
except IOError:
print(f"Error: Cannot save file {output_image_path}")
print_error(f"Cannot save file {output_image_path}")
image.close()
exit(1)
def print_error(string):
print(f"resize-img Error: {string}")
def rotate_image(image):
exif = image.getexif()
if exif is None: