Photo: Scale down an image for a local message thumbnail (#3423)
This commit is contained in:
parent
18bfe2bd96
commit
193a0c60f8
@ -1439,7 +1439,7 @@ function buildUploadingMedia(
|
|||||||
photo: {
|
photo: {
|
||||||
id: LOCAL_MEDIA_UPLOADING_TEMP_ID,
|
id: LOCAL_MEDIA_UPLOADING_TEMP_ID,
|
||||||
sizes: [],
|
sizes: [],
|
||||||
thumbnail: { width, height, dataUri: blobUrl },
|
thumbnail: { width, height, dataUri: previewBlobUrl || blobUrl },
|
||||||
blobUrl,
|
blobUrl,
|
||||||
isSpoiler: shouldSendAsSpoiler,
|
isSpoiler: shouldSendAsSpoiler,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import {
|
|||||||
import { scaleImage } from '../../../../util/imageResize';
|
import { scaleImage } from '../../../../util/imageResize';
|
||||||
|
|
||||||
const MAX_QUICK_IMG_SIZE = 1280; // px
|
const MAX_QUICK_IMG_SIZE = 1280; // px
|
||||||
|
const MAX_THUMB_IMG_SIZE = 40; // px
|
||||||
const MAX_ASPECT_RATIO = 20;
|
const MAX_ASPECT_RATIO = 20;
|
||||||
const FILE_EXT_REGEX = /\.[^/.]+$/;
|
const FILE_EXT_REGEX = /\.[^/.]+$/;
|
||||||
|
|
||||||
@ -53,7 +54,14 @@ export default async function buildAttachment(
|
|||||||
quick = { width, height };
|
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)) {
|
} else if (SUPPORTED_VIDEO_CONTENT_TYPES.has(mimeType)) {
|
||||||
const { videoWidth: width, videoHeight: height, duration } = await preloadVideo(blobUrl);
|
const { videoWidth: width, videoHeight: height, duration } = await preloadVideo(blobUrl);
|
||||||
shouldSendAsFile = !validateAspectRatio(width, height);
|
shouldSendAsFile = !validateAspectRatio(width, height);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user