@shangxueink/koishi-plugin-puppeteer-without-canvas
Version:
28 lines (25 loc) • 844 B
HTML
<html>
<head>
<script>
window.base64ToUint8Array = 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.buffer
}
window.loadImage = function (id, base64, type) {
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([base64ToUint8Array(base64)], { type })
image.src = URL.createObjectURL(blob)
document.body.appendChild(image)
})
}
</script>
</head>
</html>