Allow sending and thumbnailing AVIF images (#8172)
parent
4e665dedb9
commit
cd15e08fc2
|
@ -249,15 +249,20 @@ async function infoForImageFile(matrixClient: MatrixClient, roomId: string, imag
|
||||||
const result = await createThumbnail(imageElement.img, imageElement.width, imageElement.height, thumbnailType);
|
const result = await createThumbnail(imageElement.img, imageElement.width, imageElement.height, thumbnailType);
|
||||||
const imageInfo = result.info;
|
const imageInfo = result.info;
|
||||||
|
|
||||||
// we do all sizing checks here because we still rely on thumbnail generation for making a blurhash from.
|
// For lesser supported image types, always include the thumbnail even if it is larger
|
||||||
const sizeDifference = imageFile.size - imageInfo.thumbnail_info.size;
|
if (!["image/avif", "image/webp"].includes(imageFile.type)) {
|
||||||
if (
|
// we do all sizing checks here because we still rely on thumbnail generation for making a blurhash from.
|
||||||
imageFile.size <= IMAGE_SIZE_THRESHOLD_THUMBNAIL || // image is small enough already
|
const sizeDifference = imageFile.size - imageInfo.thumbnail_info.size;
|
||||||
(sizeDifference <= IMAGE_THUMBNAIL_MIN_REDUCTION_SIZE && // thumbnail is not sufficiently smaller than original
|
if (
|
||||||
sizeDifference <= (imageFile.size * IMAGE_THUMBNAIL_MIN_REDUCTION_PERCENT))
|
// image is small enough already
|
||||||
) {
|
imageFile.size <= IMAGE_SIZE_THRESHOLD_THUMBNAIL ||
|
||||||
delete imageInfo["thumbnail_info"];
|
// thumbnail is not sufficiently smaller than original
|
||||||
return imageInfo;
|
(sizeDifference <= IMAGE_THUMBNAIL_MIN_REDUCTION_SIZE &&
|
||||||
|
sizeDifference <= (imageFile.size * IMAGE_THUMBNAIL_MIN_REDUCTION_PERCENT))
|
||||||
|
) {
|
||||||
|
delete imageInfo["thumbnail_info"];
|
||||||
|
return imageInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadResult = await uploadFile(matrixClient, roomId, result.thumbnail);
|
const uploadResult = await uploadFile(matrixClient, roomId, result.thumbnail);
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
import { arrayHasDiff } from "./arrays";
|
import { arrayHasDiff } from "./arrays";
|
||||||
|
|
||||||
export function mayBeAnimated(mimeType: string): boolean {
|
export function mayBeAnimated(mimeType: string): boolean {
|
||||||
return ["image/gif", "image/webp", "image/png", "image/apng"].includes(mimeType);
|
// AVIF animation support at the time of writing is only available in Chrome hence not having `blobIsAnimated` check
|
||||||
|
return ["image/gif", "image/webp", "image/png", "image/apng", "image/avif"].includes(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
function arrayBufferRead(arr: ArrayBuffer, start: number, len: number): Uint8Array {
|
function arrayBufferRead(arr: ArrayBuffer, start: number, len: number): Uint8Array {
|
||||||
|
|
|
@ -54,6 +54,7 @@ const ALLOWED_BLOB_MIMETYPES = [
|
||||||
'image/png',
|
'image/png',
|
||||||
'image/apng',
|
'image/apng',
|
||||||
'image/webp',
|
'image/webp',
|
||||||
|
'image/avif',
|
||||||
|
|
||||||
'video/mp4',
|
'video/mp4',
|
||||||
'video/webm',
|
'video/webm',
|
||||||
|
|
Loading…
Reference in New Issue