I worked on my chrome app and the content security policity was nerving. I wanted to get a jpeg image from a json (string/object/array I don't know), but the csp stopped me everytime. Now I know that it's easier with data-links, so I searched a converter.
function getdt(img) {
// Create an empty canvas element
var canvas = document.createElement("canvas");
// Copy the image contents to the canvas
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
// Get the data-URL formatted image.
var dataURL = canvas.toDataURL("image/png");
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}
//Example
getdt('http://ms01.oe3.fm/oe3metafiles/Pictures/200/929203.22.jpg');
Unfortunately this doesn't work. The Error message is this:
Uncaught TypeError:
Failed to execute 'drawImage' on 'CanvasRenderingContext2D':
No function was found that matched the signature provided.
I hope someone can help me :) Sorry for my bad english