1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00

fix: Improve quality of resized images

This commit is contained in:
Maksim Eltyshev 2022-12-26 22:43:21 +01:00
parent 5cd025ffb7
commit 0ad9cffb08
4 changed files with 159 additions and 9 deletions

View file

@ -47,13 +47,20 @@ module.exports = {
fs.mkdirSync(thumbnailsPath);
const { width, pageHeight: height = metadata.height } = metadata;
const isPortrait = height > width;
const thumbnailsExtension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
try {
await image
.resize(256, height > width ? 320 : undefined, {
kernel: sharp.kernel.nearest,
})
.resize(
256,
isPortrait ? 320 : undefined,
width < 256 || (isPortrait && height < 320)
? {
kernel: sharp.kernel.nearest,
}
: undefined,
)
.toFile(path.join(thumbnailsPath, `cover-256.${thumbnailsExtension}`));
fileData.image = {