JS图片转BASE64编码
<script>
function image2Base64(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var dataURL = canvas.toDataURL("image/png");
return dataURL;
}
function getImgBase64(imgsrc){
var base64="";
var img = new Image();
img.src=imgsrc;
img.onload=function(){
base64 = image2Base64(img);
console.log(base64);
}
}
getImgBase64("img.png");
</script>
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询