From 2652a01f678081a5629442d2b4be516f14a4f241 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 8 Jul 2022 15:00:18 +0200 Subject: [PATCH] Composer: Fix unnecessary image scaling (#1931) --- src/components/middle/composer/helpers/buildAttachment.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/middle/composer/helpers/buildAttachment.ts b/src/components/middle/composer/helpers/buildAttachment.ts index 3ed385035..39427a341 100644 --- a/src/components/middle/composer/helpers/buildAttachment.ts +++ b/src/components/middle/composer/helpers/buildAttachment.ts @@ -29,9 +29,12 @@ export default async function buildAttachment( if (isQuick) { const img = await preloadImage(blobUrl); const { width, height } = img; + const shouldShrink = width > MAX_QUICK_IMG_SIZE || height > MAX_QUICK_IMG_SIZE; - if (width > MAX_QUICK_IMG_SIZE || height > MAX_QUICK_IMG_SIZE || mimeType !== 'image/jpeg') { - const resizedUrl = await scaleImage(blobUrl, MAX_QUICK_IMG_SIZE / Math.max(width, height), 'image/jpeg'); + if (shouldShrink || mimeType !== 'image/jpeg') { + const resizedUrl = await scaleImage( + blobUrl, shouldShrink ? MAX_QUICK_IMG_SIZE / Math.max(width, height) : 1, 'image/jpeg', + ); URL.revokeObjectURL(blobUrl); const newBlob = await fetchBlob(resizedUrl); return buildAttachment(filename, newBlob, true, options);