thumbnailer: use png

Use png instead of jpg for transparency
Also don't thumbnail images smaller than thumbnail size
This commit is contained in:
2 * r + 2 * t 2025-04-01 16:42:52 +11:00
parent 3d4577044e
commit a7de222b0f

View file

@ -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<string> {
@ -40,6 +45,8 @@ export default class Thumbnailer {
}
static async thumbnail(path: string): Promise<string> {
if (!(await this.shouldThumbnail(path))) return path;
let thumbPath = this.getThumbPath(path);
// If not lazy (i.e. force gen), delete existing thumbnail