Is there a way to convert an image into base 64 using angular5 when the image is sourced from Facebook or Google authentication API?
I seem to be encountering an issue, what could I be doing wrong?
getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = img.src.width;
canvas.height = img.src.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL("image/png");
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}
// Usage
var url=" https://www.livemint.com/rf/Image-621x414/LiveMint/Period2/2017/06/12/Photos/Opinion/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d594841484e42400046401500001b1f1c55191c196d61445b486044435903677d6a">[email protected]</a>";
var base64 = this.getBase64Image(url);
//error
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'width' of undefined TypeError: Cannot read property 'width' of undefined