From a7de222b0f98b636b269993ba20fa69192060a12 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Tue, 1 Apr 2025 16:42:52 +1100 Subject: thumbnailer: use png Use png instead of jpg for transparency Also don't thumbnail images smaller than thumbnail size --- src/utils/thumbnailer.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/utils/thumbnailer.ts b/src/utils/thumbnailer.ts index ffd1c67..7551870 100644 --- a/src/utils/thumbnailer.ts +++ b/src/utils/thumbnailer.ts @@ -14,7 +14,12 @@ export default class Thumbnailer { static getThumbPath(path: string) { const dir = path.slice(path.indexOf("/") + 1, path.lastIndexOf("/")).replaceAll("/", "-"); - return `${this.thumbnailDir}/${dir}-${basename(path)}.jpg`; + return `${this.thumbnailDir}/${dir}-${basename(path)}.png`; + } + + static async shouldThumbnail(path: string) { + const [width, height] = (await execAsync(`identify -ping -format "%w %h" ${path}`)).split(" ").map(parseInt); + return width > this.thumbWidth || height > this.thumbHeight; } static async #thumbnail(path: string, attempts: number): Promise { @@ -40,6 +45,8 @@ export default class Thumbnailer { } static async thumbnail(path: string): Promise { + if (!(await this.shouldThumbnail(path))) return path; + let thumbPath = this.getThumbPath(path); // If not lazy (i.e. force gen), delete existing thumbnail -- cgit v1.2.3-freya