mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +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 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user