mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
make toBlob work on IE11
This commit is contained in:
parent
a930dec8db
commit
6f94ca1a4a
@ -53,10 +53,16 @@ export class ImageHandle {
|
|||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
const img = await this._getImgElement();
|
const img = await this._getImgElement();
|
||||||
ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);
|
ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);
|
||||||
const mimeType = this.blob.mimeType === "image/jpeg" ? "image/jpeg" : "image/png";
|
let mimeType = this.blob.mimeType === "image/jpeg" ? "image/jpeg" : "image/png";
|
||||||
const nativeBlob = await new Promise(resolve => {
|
let nativeBlob;
|
||||||
canvas.toBlob(resolve, mimeType);
|
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);
|
const blob = BlobHandle.fromBlob(nativeBlob);
|
||||||
return new ImageHandle(blob, scaledWidth, scaledHeight, null);
|
return new ImageHandle(blob, scaledWidth, scaledHeight, null);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user