diff --git a/src/api/gramjs/apiBuilders/messages.ts b/src/api/gramjs/apiBuilders/messages.ts index 4fbff39b1..cb1480b85 100644 --- a/src/api/gramjs/apiBuilders/messages.ts +++ b/src/api/gramjs/apiBuilders/messages.ts @@ -1439,7 +1439,7 @@ function buildUploadingMedia( photo: { id: LOCAL_MEDIA_UPLOADING_TEMP_ID, sizes: [], - thumbnail: { width, height, dataUri: blobUrl }, + thumbnail: { width, height, dataUri: previewBlobUrl || blobUrl }, blobUrl, isSpoiler: shouldSendAsSpoiler, }, diff --git a/src/components/middle/composer/helpers/buildAttachment.ts b/src/components/middle/composer/helpers/buildAttachment.ts index 7b2feb10c..950d80ec1 100644 --- a/src/components/middle/composer/helpers/buildAttachment.ts +++ b/src/components/middle/composer/helpers/buildAttachment.ts @@ -14,6 +14,7 @@ import { import { scaleImage } from '../../../../util/imageResize'; const MAX_QUICK_IMG_SIZE = 1280; // px +const MAX_THUMB_IMG_SIZE = 40; // px const MAX_ASPECT_RATIO = 20; const FILE_EXT_REGEX = /\.[^/.]+$/; @@ -53,7 +54,14 @@ export default async function buildAttachment( quick = { width, height }; } - previewBlobUrl = blobUrl; + const shouldShrinkPreview = Math.max(width, height) > MAX_THUMB_IMG_SIZE; + if (shouldShrinkPreview) { + previewBlobUrl = await scaleImage( + blobUrl, MAX_THUMB_IMG_SIZE / Math.max(width, height), 'image/jpeg', + ); + } else { + previewBlobUrl = blobUrl; + } } else if (SUPPORTED_VIDEO_CONTENT_TYPES.has(mimeType)) { const { videoWidth: width, videoHeight: height, duration } = await preloadVideo(blobUrl); shouldSendAsFile = !validateAspectRatio(width, height);