Uncaught Error: SecurityError: DOM Exception 18 Canvas
<pre><code>function getBase64Image(img) {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    document.body.appendChild(canvas);
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0);
    var dataURL = canvas.toDataURL("image/png");
    return dataURL;
}   
</code></pre>

<p>I seem to be violating something, just can't seem to find what. Any help on how to fix it?</p>
