We write the contents of the image file directly into the HTML file. The advantage of this is that it saves an HTTP request. The disadvantage is that the browser will not cache such images. 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 simple example of converting image connections into base64 format by js is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.