From 2bc82d557aec91bfe44e330eb0e5888657630ea2 Mon Sep 17 00:00:00 2001 From: Maksim Eltyshev Date: Sat, 24 Dec 2022 02:33:03 +0100 Subject: [PATCH] fix: Fix image size for animated attachments --- .../api/helpers/attachments/process-uploaded-file.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server/api/helpers/attachments/process-uploaded-file.js b/server/api/helpers/attachments/process-uploaded-file.js index 60214555..4d66bf0c 100644 --- a/server/api/helpers/attachments/process-uploaded-file.js +++ b/server/api/helpers/attachments/process-uploaded-file.js @@ -46,18 +46,20 @@ module.exports = { const thumbnailsPath = path.join(rootPath, 'thumbnails'); fs.mkdirSync(thumbnailsPath); - const extension = metadata.format === 'jpeg' ? 'jpg' : metadata.format; + const { width, pageHeight: height = metadata.height } = metadata; + const thumbnailsExtension = metadata.format === 'jpeg' ? 'jpg' : metadata.format; try { await image - .resize(256, metadata.height > metadata.width ? 320 : undefined, { + .resize(256, height > width ? 320 : undefined, { kernel: sharp.kernel.nearest, }) - .toFile(path.join(thumbnailsPath, `cover-256.${extension}`)); + .toFile(path.join(thumbnailsPath, `cover-256.${thumbnailsExtension}`)); fileData.image = { - ..._.pick(metadata, ['width', 'height']), - thumbnailsExtension: extension, + width, + height, + thumbnailsExtension, }; } catch (error1) { try {