1
0
mirror of https://github.com/elk-zone/elk synced 2024-12-25 20:17:59 +09:00
elk/composables/utils.ts

17 lines
444 B
TypeScript
Raw Normal View History

2022-11-21 22:21:53 +09:00
export function getDataUrlFromArr(arr: Uint8ClampedArray, w: number, h: number) {
if (typeof w === 'undefined' || typeof h === 'undefined')
w = h = Math.sqrt(arr.length / 4)
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')!
canvas.width = w
canvas.height = h
const imgData = ctx.createImageData(w, h)
imgData.data.set(arr)
ctx.putImageData(imgData, 0, 0)
return canvas.toDataURL()
}