Composer: Fix image uploading on Firefox <93 (#1457)
This commit is contained in:
parent
2a144b9941
commit
36326de4c5
@ -41,20 +41,25 @@ 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) {
|
||||||
const bitmap = await window.createImageBitmap(img,
|
try {
|
||||||
{ resizeWidth: width, resizeHeight: height, resizeQuality: 'high' });
|
const bitmap = await window.createImageBitmap(img,
|
||||||
return new Promise((res) => {
|
{ resizeWidth: width, resizeHeight: height, resizeQuality: 'high' });
|
||||||
const canvas = document.createElement('canvas');
|
return await new Promise((res) => {
|
||||||
canvas.width = bitmap.width;
|
const canvas = document.createElement('canvas');
|
||||||
canvas.height = bitmap.height;
|
canvas.width = bitmap.width;
|
||||||
const ctx = canvas.getContext('bitmaprenderer');
|
canvas.height = bitmap.height;
|
||||||
if (ctx) {
|
const ctx = canvas.getContext('bitmaprenderer');
|
||||||
ctx.transferFromImageBitmap(bitmap);
|
if (ctx) {
|
||||||
} else {
|
ctx.transferFromImageBitmap(bitmap);
|
||||||
canvas.getContext('2d')!.drawImage(bitmap, 0, 0);
|
} else {
|
||||||
}
|
canvas.getContext('2d')!.drawImage(bitmap, 0, 0);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user