From afc77eec1ef8423b61cb4b761534609b5033d937 Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 1 Apr 2024 12:12:00 +0700 Subject: [PATCH] fix h --- pkgs/api/_img.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/api/_img.ts b/pkgs/api/_img.ts index 57818f0..0b68f3c 100644 --- a/pkgs/api/_img.ts +++ b/pkgs/api/_img.ts @@ -15,6 +15,7 @@ export const _ = { let res = new Response("NOT FOUND", { status: 404 }); const w = parseInt(req.query_parameters.w); + const h = parseInt(req.query_parameters.h); const format = req.query_parameters.f; let force = typeof req.query_parameters.force === "string"; @@ -37,7 +38,7 @@ export const _ = { force = true; } - if (!w) { + if (!w && !h) { const file = Bun.file(filepath); return new Response(file); } else { @@ -61,7 +62,14 @@ export const _ = { if (force) { const img = sharp(await original.arrayBuffer()); - let out = img.resize({ width: w, fit: "inside" }); + const arg: any = { fit: "inside" }; + if (w) { + arg.width = w; + } + if (h) { + arg.width = h; + } + let out = img.resize(arg); if (format === "jpg" && !file_name.endsWith(".jpg")) { file_name = file_name + ".jpg";