如何使用javascript将https URL图像转换为base64字符串?

时间:2016-07-28 13:07:38

标签: javascript image https base64

Check the code in JSFiddle此代码显示错误。

var img = document.querySelector("img");
var img1 = new Image();
             img1.crossOrigin = 'Anonymous';
             img1.onload = function() {
             var canvas = document.createElement('CANVAS');
             var ctx = canvas.getContext('2d');
             var dataURL;
             canvas.height = this.height;
             canvas.width = this.width;
             document.body.appendChild(canvas);
             ctx.drawImage(this, 0, 0);
             dataURL = canvas.toDataURL();
             console.log(dataURL);
             };

    img1.src = "https://bithin.files.wordpress.com/2012/02/https.jpg";

错误:

来自原作的图片' https://bithin.files.wordpress.com'已被跨源资源共享策略阻止加载:否Access-Control-Allow-Origin'标头出现在请求的资源上。起源' http://fiddle.jshell.net'因此不允许访问。

0 个答案:

没有答案