diff --git a/backend/middlewares/thumbnail/THRenderers.ts b/backend/middlewares/thumbnail/THRenderers.ts index ad855aa5..3ca1c279 100644 --- a/backend/middlewares/thumbnail/THRenderers.ts +++ b/backend/middlewares/thumbnail/THRenderers.ts @@ -5,6 +5,7 @@ export interface RendererInput { size: number; makeSquare: boolean; thPath: string; + qualityPriority: boolean, __dirname: string; } @@ -13,6 +14,9 @@ export const softwareRenderer = (input: RendererInput, done) => { //generate thumbnail const Jimp = require("jimp"); Jimp.read(input.imagePath).then((image) => { + + const Logger = require(input.__dirname + "/../../Logger").Logger; + Logger.silly("[SoftwareThRenderer] rendering thumbnail:", input.imagePath); /** * newWidth * newHeight = size*size * newHeight/newWidth = height/width @@ -23,12 +27,13 @@ export const softwareRenderer = (input: RendererInput, done) => { * @type {number} */ const ratio = image.bitmap.height / image.bitmap.width; + const algo = input.qualityPriority == true ? Jimp.RESIZE_BEZIER : Jimp.RESIZE_NEAREST_NEIGHBOR; if (input.makeSquare == false) { let newWidth = Math.sqrt((input.size * input.size) / ratio); - image.resize(newWidth, Jimp.AUTO, Jimp.RESIZE_BEZIER); + image.resize(newWidth, Jimp.AUTO, algo); } else { - image.resize(input.size / Math.min(ratio, 1), Jimp.AUTO, Jimp.RESIZE_BEZIER); + image.resize(input.size / Math.min(ratio, 1), Jimp.AUTO, algo); image.crop(0, 0, input.size, input.size); } image.quality(60); // set JPEG quality @@ -51,6 +56,9 @@ export const hardwareRenderer = (input: RendererInput, done) => { image .metadata() .then((metadata: Metadata) => { + + const Logger = require(input.__dirname + "/../../Logger").Logger; + Logger.silly("[SoftwareThRenderer] rendering thumbnail:", input.imagePath); /** * newWidth * newHeight = size*size * newHeight/newWidth = height/width @@ -62,13 +70,21 @@ export const hardwareRenderer = (input: RendererInput, done) => { */ try { const ratio = metadata.height / metadata.width; + const kernel = input.qualityPriority == true ? sharp.kernel.lanczos3 : sharp.kernel.nearest; + const interpolator = input.qualityPriority == true ? sharp.interpolator.bicubic : sharp.interpolator.nearest; if (input.makeSquare == false) { const newWidth = Math.round(Math.sqrt((input.size * input.size) / ratio)); - image.resize(newWidth); + image.resize(newWidth, null, { + kernel: kernel, + interpolator: interpolator + }); } else { image - .resize(input.size, input.size) + .resize(input.size, input.size, { + kernel: kernel, + interpolator: interpolator + }) .crop(sharp.strategy.center); } image diff --git a/backend/middlewares/thumbnail/ThumbnailGeneratorMWs.ts b/backend/middlewares/thumbnail/ThumbnailGeneratorMWs.ts index fe70b54c..33f911b2 100644 --- a/backend/middlewares/thumbnail/ThumbnailGeneratorMWs.ts +++ b/backend/middlewares/thumbnail/ThumbnailGeneratorMWs.ts @@ -139,7 +139,14 @@ export class ThumbnailGeneratorMWs { this.initPools(); //run on other thread - pool.send({imagePath: imagePath, size: size, thPath: thPath, makeSquare: makeSquare, __dirname: __dirname}) + pool.send({ + imagePath: imagePath, + size: size, + thPath: thPath, + makeSquare: makeSquare, + qualityPriority: Config.Server.thumbnail.qualityPriority, + __dirname: __dirname, + }) .on('done', (out) => { return next(out); }).on('error', (error) => { diff --git a/common/config/private/IPrivateConfig.ts b/common/config/private/IPrivateConfig.ts index ff020880..66f5ba2c 100644 --- a/common/config/private/IPrivateConfig.ts +++ b/common/config/private/IPrivateConfig.ts @@ -18,6 +18,7 @@ export interface DataBaseConfig { export interface ThumbnailConfig { folder: string; hardwareAcceleration: boolean; + qualityPriority: boolean; } export interface ServerConfig { diff --git a/common/config/private/PrivateConfigClass.ts b/common/config/private/PrivateConfigClass.ts index 08abda9b..7a43e0c2 100644 --- a/common/config/private/PrivateConfigClass.ts +++ b/common/config/private/PrivateConfigClass.ts @@ -12,7 +12,8 @@ export class PrivateConfigClass extends PublicConfigClass { imagesFolder: "demo/images", thumbnail: { folder: "demo/TEMP", - hardwareAcceleration: true + hardwareAcceleration: true, + qualityPriority: true }, database: { type: DatabaseType.mysql,