1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +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 = {

View file

@ -37,15 +37,22 @@ module.exports = {
fs.mkdirSync(rootPath);
const { width, pageHeight: height = metadata.height } = metadata;
const extension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
try {
await image.toFile(path.join(rootPath, `original.${extension}`));
await image
.resize(336, 200, {
kernel: sharp.kernel.nearest,
})
.resize(
336,
200,
width < 336 || height < 200
? {
kernel: sharp.kernel.nearest,
}
: undefined,
)
.toFile(path.join(rootPath, `cover-336.${extension}`));
} catch (error1) {
try {

View file

@ -37,15 +37,22 @@ module.exports = {
fs.mkdirSync(rootPath);
const { width, pageHeight: height = metadata.height } = metadata;
const extension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
try {
await image.toFile(path.join(rootPath, `original.${extension}`));
await image
.resize(100, 100, {
kernel: sharp.kernel.nearest,
})
.resize(
100,
100,
width < 100 || height < 100
? {
kernel: sharp.kernel.nearest,
}
: undefined,
)
.toFile(path.join(rootPath, `square-100.${extension}`));
} catch (error1) {
try {