about summary refs log tree commit diff
path: root/src/lib/canvas.ts
blob: 760c0e67f3f711a81deabb23fc4ebd7e55f416fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export const getCanvas = (base64: string): Promise<HTMLCanvasElement> => {
  return new Promise(resolve => {
    const image = new Image()
    image.onload = () => {
      const canvas = document.createElement('canvas')
      canvas.width = image.width
      canvas.height = image.height

      const ctx = canvas.getContext('2d')
      ctx?.drawImage(image, 0, 0)
      resolve(canvas)
    }
    image.src = base64
  })
}