I need images to be copied and sent to server for image rotations etc.
To copy an image I'm using this code( from Get image data in JavaScript?):
function getBase64Image(img) {
    // Create an empty canvas element
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0);
    var dataURL = canvas.toDataURL("image/png");
    var replaced = dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
    console.log("dataurl=",dataURL);
    console.log("replaced=",replaced);
    return replaced;
}
It is called like this:
$("#xyz").load(send_image).each(function () {
            if (this.complete)
                $(this).load();
        });
function send_image(){
      getBase64Image(document.getElementById('xyz'));
}
However in getBase64Image function once in 40-50 times dataURL is being returned as empty.
What could be the reason?
 
    