make toBlob work on IE11

This commit is contained in:
Bruno Windels 2020-11-18 16:28:48 +01:00
parent a930dec8db
commit 6f94ca1a4a

View File

@ -53,10 +53,16 @@ export class ImageHandle {
const ctx = canvas.getContext("2d");
const img = await this._getImgElement();
ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);
const mimeType = this.blob.mimeType === "image/jpeg" ? "image/jpeg" : "image/png";
const nativeBlob = await new Promise(resolve => {
canvas.toBlob(resolve, mimeType);
});
let mimeType = this.blob.mimeType === "image/jpeg" ? "image/jpeg" : "image/png";
let nativeBlob;
if (canvas.toBlob) {
nativeBlob = await new Promise(resolve => canvas.toBlob(resolve, mimeType));
} else if (canvas.msToBlob) {
mimeType = "image/png";
nativeBlob = canvas.msToBlob();
} else {
throw new Error("canvas can't be turned into blob");
}
const blob = BlobHandle.fromBlob(nativeBlob);
return new ImageHandle(blob, scaledWidth, scaledHeight, null);
}