forked from Hubs-Foundation/hubs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
801079c
commit 5c0af84
Showing
3 changed files
with
24 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const createImageBitmap = | ||
window.createImageBitmap || | ||
async function(data) { | ||
return new Promise(resolve => { | ||
// https://dev.to/nektro/createimagebitmap-polyfill-for-safari-and-edge-228 | ||
// https://gist.github.com/MonsieurV/fb640c29084c171b4444184858a91bc7 | ||
|
||
const canvas = document.createElement("canvas"); | ||
const ctx = canvas.getContext("2d"); | ||
canvas.width = data.width; | ||
canvas.height = data.height; | ||
ctx.putImageData(data, 0, 0); | ||
const dataURL = canvas.toDataURL(); | ||
const img = document.createElement("img"); | ||
|
||
img.addEventListener("load", function() { | ||
resolve(this); | ||
}); | ||
|
||
img.src = dataURL; | ||
}); | ||
}; |