<script>
function ImgToBase64(img) {
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.height = img.height;
canvas.width = img.width;
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL('image/png');
img.removeAttribute("onload");
img.src = dataURL;
canvas = null;
}
</script>
<img onl oad="ImgToBase64(this)" crossorigin="anonymous" src="xxxxxxxx" />
标签:canvas,dataURL,跨域,img,base64,height,var,图片 From: https://www.cnblogs.com/QJZY/p/17420200.html