image轉base64

function imgToBase64(url) {
        var canvas=document.createElement('canvas');
        var ctx=canvas.getContext('2d');
        var img=new Image();
        img.onload=function () {
            ctx.drawImage(img,0,0);
            var b64=canvas.toDataURL('image/png');
            canvas=null;
            return b64;
        }
        img.src=url;
    }
相關文章
相關標籤/搜索