跨域图片转base64
<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 onload="ImgToBase64(this)" crossorigin="anonymous" src="xxxxxxxx" />