-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): support loadImage for canvas service
- Loading branch information
Showing
3 changed files
with
121 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
<html></html> | ||
<html> | ||
<head> | ||
<script> | ||
window.base64ToArrayBuffer = function (base64) { | ||
const binary = atob(base64.replace(/\\s/g, '')) | ||
const buffer = new Uint8Array(binary.length) | ||
for (let i = 0; i < binary.length; i++) { | ||
buffer[i] = binary.charCodeAt(i) | ||
} | ||
return buffer | ||
} | ||
|
||
window.loadImage = function (id, base64) { | ||
return new Promise((resolve, reject) => { | ||
const image = document.createElement('img') | ||
image.id = id | ||
image.onload = () => resolve({ width: image.naturalWidth, height: image.naturalHeight }) | ||
image.onerror = reject | ||
const blob = new Blob([base64ToArrayBuffer(base64)]) | ||
image.src = URL.createObjectURL(blob) | ||
document.body.appendChild(image) | ||
}) | ||
} | ||
</script> | ||
</head> | ||
</html> |
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