圖片連接轉成base64

一半須要個人圖像轉換爲base64字符串,這樣咱們能夠把個人形象到服務器。如今咱們提供一個js:canvas

function convertImgToBase64(url, callback, outputFormat){var canvas = document.createElement('CANVAS'), ctx = canvas.getContext('2d'), img =newImage; 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});
相關文章
相關標籤/搜索