How to get Base64 image from an URL or Image tag

You might need to convert a png/jpeg image to a base64 encoding. The following function does that for you. function getBase64FromImageUrl(url) { var img = new Image(); img.setAttribute(‘crossOrigin’, ‘anonymous’); 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); var dataURL = canvas.toDataURL(“image/png”); var url= […]

Continue reading