I am trying to get base64 string representation of an image giving its URL.
HTML:
<input type="text" value="" id="urlFileUpload"/>
<input type="button" id="btn" value="GO" />
JS:
$('#btn').click(function()
{
var img = new Image();
img.src = $('#urlFileUpload').val();
img.onload = function ()
{
var canvas = document.createElement("canvas");
canvas.width = this.width;
canvas.height = this.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
console.log(canvas.toDataURL("image/png"));
}
});
I get this error: Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
Here is a JSFiddle.