[Javascript] canvas操作
canvasを扱う備忘録
画像をcanvasタグで表示する
const img = new Image()
img.src = "%url"
img.onload = (e => {
const img = e.target
const canvas = document.createElement("canvas")
const ctx = canvas.getContext("2d")
const w = img.naturalWidth
const h = img.naturalHeight
canvas.width = w
canvas.height = h
ctx.drawImage(img, 0, 0, w, h)
return canvas
})