Merge pull request #647 from TriliumNext/renovate/jimp-1.x

fix(deps): update dependency jimp to v1
This commit is contained in:
Elian Doran 2024-12-10 23:06:29 +02:00 committed by GitHub
commit d204aca228
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 856 additions and 395 deletions

1241
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -99,7 +99,7 @@
"ini": "5.0.0",
"is-animated": "2.0.2",
"is-svg": "4.4.0",
"jimp": "0.22.12",
"jimp": "1.6.0",
"joplin-turndown-plugin-gfm": "1.0.12",
"jquery": "3.7.1",
"jquery-hotkeys": "0.2.2",

View File

@ -6,7 +6,7 @@ import protectedSessionService from "./protected_session.js";
import noteService from "./notes.js";
import optionService from "./options.js";
import sql from "./sql.js";
import jimp from "jimp";
import { Jimp } from "jimp";
import imageType from "image-type";
import sanitizeFilename from "sanitize-filename";
import isSvg from "is-svg";
@ -212,21 +212,19 @@ async function resize(buffer: Buffer, quality: number) {
const start = Date.now();
const image = await jimp.read(buffer);
const image = await Jimp.read(buffer);
if (image.bitmap.width > image.bitmap.height && image.bitmap.width > imageMaxWidthHeight) {
image.resize(imageMaxWidthHeight, jimp.AUTO);
image.resize({ w: imageMaxWidthHeight });
}
else if (image.bitmap.height > imageMaxWidthHeight) {
image.resize(jimp.AUTO, imageMaxWidthHeight);
image.resize({ h: imageMaxWidthHeight });
}
image.quality(quality);
// when converting PNG to JPG, we lose the alpha channel, this is replaced by white to match Trilium white background
image.background(0xFFFFFFFF);
image.background = 0xFFFFFFFF;
const resultBuffer = await image.getBufferAsync(jimp.MIME_JPEG);
const resultBuffer = await image.getBuffer("image/jpeg", { quality });
log.info(`Resizing image of ${resultBuffer.byteLength} took ${Date.now() - start}ms`);