From 257fa54da6b732908ce3d3351bb318fad6b7cdca Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sat, 26 Aug 2023 22:42:25 +0800 Subject: [PATCH] Bug fix --- routes/thumbnail/[id].ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/routes/thumbnail/[id].ts b/routes/thumbnail/[id].ts index bbe9ee3..6d91a08 100644 --- a/routes/thumbnail/[id].ts +++ b/routes/thumbnail/[id].ts @@ -2,7 +2,11 @@ import { Handlers } from "$fresh/server.ts"; import { exists } from "std/fs/exists.ts"; import { get_task_manager } from "../../server.ts"; import { parse_int } from "../../server/parse_form.ts"; -import { generate_filename, ThumbnailConfig } from "../../thumbnail/base.ts"; +import { + generate_filename, + ThumbnailConfig, + ThumbnailGenMethod, +} from "../../thumbnail/base.ts"; import { sure_dir } from "../../utils.ts"; import { get_file_response, @@ -50,23 +54,28 @@ export const handler: Handlers = { const width = await parse_int(u.searchParams.get("width"), null); const height = await parse_int(u.searchParams.get("height"), null); const quality = await parse_int(u.searchParams.get("quality"), 1); - const cfg: ThumbnailConfig = { width: 0, height: 0, quality }; + const cfg: ThumbnailConfig = { + width: 0, + height: 0, + quality, + method: ThumbnailGenMethod.Unknown, + }; if (width !== null && height !== null) { cfg.width = width; cfg.height = height; } else if (width !== null) { cfg.width = width; - cfg.height = Math.round(f.height / f.width * width); + cfg.height = Math.floor(f.height / f.width * width); } else if (height !== null) { cfg.height = height; - cfg.width = Math.round(f.width / f.height * height); + cfg.width = Math.floor(f.width / f.height * height); } else { if (f.width > f.height) { cfg.width = max; - cfg.height = Math.round(f.height / f.width * max); + cfg.height = Math.floor(f.height / f.width * max); } else { cfg.height = max; - cfg.width = Math.round(f.width / f.height * max); + cfg.width = Math.floor(f.width / f.height * max); } } const output = generate_filename(b, f, cfg);