本地图片url转Base64

  function  convertImgToBase64(url, callback, outputFormat) {
            var img = new Image;
            img.crossOrigin = "Anonymous"; //跨域
            img.src = url;
            img.onload = function () {
                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(outputFormat || 'image/png');
                callback.call(this, dataURL);
                canvas = null;
            };
        },

 

上一篇:JavaScript:截取DataURL中的base64字符串


下一篇:H5 图片裁剪 - cropper 插件使用