Composer: Fix image uploading on Firefox <93 (#1457)

This commit is contained in:
Alexander Zinchuk 2021-09-19 20:54:26 +03:00
parent 2a144b9941
commit 36326de4c5

View File

@ -41,9 +41,10 @@ async function scale(
) { ) {
// Safari does not have built-in resize method with quality control // Safari does not have built-in resize method with quality control
if ('createImageBitmap' in window) { if ('createImageBitmap' in window) {
try {
const bitmap = await window.createImageBitmap(img, const bitmap = await window.createImageBitmap(img,
{ resizeWidth: width, resizeHeight: height, resizeQuality: 'high' }); { resizeWidth: width, resizeHeight: height, resizeQuality: 'high' });
return new Promise((res) => { return await new Promise((res) => {
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
canvas.width = bitmap.width; canvas.width = bitmap.width;
canvas.height = bitmap.height; canvas.height = bitmap.height;
@ -55,6 +56,10 @@ async function scale(
} }
canvas.toBlob(res, outputType); canvas.toBlob(res, outputType);
}); });
} catch (e) {
// Fallback. Firefox below 93 does not recognize `createImageBitmap` with 2 parameters
return steppedScale(img, width, height, 0.5, outputType);
}
} else { } else {
return steppedScale(img, width, height, 0.5, outputType); return steppedScale(img, width, height, 0.5, outputType);
} }