Get image data url in JavaScript?

后端 未结 8 2042
南笙
南笙 2020-11-21 05:11

I have a regular HTML page with some images (just regular HTML tags). I\'d like to get their content, base64 encoded preferably, without the need

8条回答
  •  逝去的感伤
    2020-11-21 05:44

    Use onload event to convert image after loading

    function loaded(img) {
      let c = document.createElement('canvas')
      c.getContext('2d').drawImage(img, 0, 0)
      msg.innerText= c.toDataURL();
    }
    pre { word-wrap: break-word; width: 500px; white-space: pre-wrap; }
    
    
    

提交回复
热议问题