Compare commits
No commits in common. "3c1f996342ab02e15a9583bbb04fa1261d476c83" and "a6a4d654d485bbbf1ee7fbac3f582e83190b93bb" have entirely different histories.
3c1f996342
...
a6a4d654d4
15
php/get.php
15
php/get.php
@ -65,14 +65,11 @@ function create_thumbnail(string $category, string $file): string | null {
|
||||
|
||||
$path = add_seperator_ab("/", $category, $file);
|
||||
$original_file = ROOT_DIR.IMG_DIR.$path;
|
||||
$hash = hash_file("sha1", $original_file);
|
||||
|
||||
$thumbnail_directory = ROOT_DIR.THUMBNAIL_DIR;
|
||||
$thumbnail_name = "$hash.jpg";
|
||||
$thumbnail_file = $thumbnail_directory.$thumbnail_name;
|
||||
$thumbnail_directory = ROOT_DIR.THUMBNAIL_DIR.IMG_DIR.add_seperator_ab("/", $category, "");
|
||||
$thumbnail_file = $thumbnail_directory.$file;
|
||||
|
||||
if (file_exists($thumbnail_file)) {
|
||||
log_print("thumbnail for $original_file exists, skipping generation");
|
||||
log_print("$thumbnail_file exists, skipping generation");
|
||||
goto return_thumbnail;
|
||||
}
|
||||
|
||||
@ -83,16 +80,16 @@ function create_thumbnail(string $category, string $file): string | null {
|
||||
log_error($e->getMessage());
|
||||
}
|
||||
|
||||
log_print("generating thumbnail for $original_file");
|
||||
log_print(THUMBNAIL_SCRIPT." '$original_file' '$thumbnail_file'");
|
||||
$output = shell_exec(THUMBNAIL_SCRIPT." '$original_file' '$thumbnail_file' 2>&1");
|
||||
if ($output) log_print($output);
|
||||
log_print($output);
|
||||
if ($output === false) {
|
||||
log_error("Thumbnail failed");
|
||||
return ROOT_URL.IMG_DIR.$path;
|
||||
}
|
||||
|
||||
return_thumbnail:
|
||||
return ROOT_URL.THUMBNAIL_DIR.$thumbnail_name;
|
||||
return ROOT_URL.THUMBNAIL_DIR.IMG_DIR.$path;
|
||||
}
|
||||
|
||||
function add_seperator_ab(string $separator, string $a, string $b): string {
|
||||
|
@ -4,13 +4,15 @@ import sys
|
||||
|
||||
|
||||
def main():
|
||||
target_width = 2048
|
||||
|
||||
argn = len(sys.argv)
|
||||
|
||||
if argn == 1:
|
||||
print("Error: You must specify an input file")
|
||||
print("You must specify an input file")
|
||||
exit(1)
|
||||
elif argn == 2:
|
||||
print("Error: You must specify an output file")
|
||||
print("You must specify an output file")
|
||||
exit(1)
|
||||
|
||||
input_image_path = sys.argv[1]
|
||||
@ -19,12 +21,10 @@ def main():
|
||||
try:
|
||||
image = Image.open(input_image_path)
|
||||
except IOError:
|
||||
print(f"Error: Cannot open image file {input_image_path}")
|
||||
image.close()
|
||||
print(f"Cannot open image file {input_image_path}")
|
||||
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,8 +37,7 @@ def main():
|
||||
try:
|
||||
image.save(output_image_path, **kwargs)
|
||||
except IOError:
|
||||
print(f"Error: Cannot save file {output_image_path}")
|
||||
image.close()
|
||||
print(f"Cannot save file {output_image_path}")
|
||||
exit(1)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user