The benefit of this is that we have written the contents of the image file directly in the HTML file, saving an HTTP request. The downside is that browsers do not cache this image. Now we provide a JS:
function convertImgToBase64 (URL, callback, OutputFormat) {
var canvas = document.createelement (' canvas '),
CTX = Canvas.getcontext (' 2d '),
img = new Image;
Img.crossorigin = ' Anonymous ';
Img.onload = function () {
canvas.height = img.height;
Canvas.width = Img.width;
Ctx.drawimage (img,0,0);
var dataurl = canvas.todataurl (OutputFormat | | ' Image/png ');
Callback.call (this, dataurl);
canvas = null;
img.src = URL;
}
ConvertImgToBase64 (' Http://bit.ly/18g0VNp ', function (base64img) {
//Base64dataurl
});
The above JS will picture connection conversion into Base64 format Simple example is small set to share all the content, hope to give you a reference, also hope that we support cloud habitat community.