JS將圖片轉爲base64

var getDataFromImg = function(img) { var canvas = document.createElement('canvas'); var context = canvas.getContext('2d'); context.drawImage(img, 0, 0 ); var dataURL = canvas.toDataURL('image/png'); return dataURL.replace(/^data:image\/(png|jpg);base64,/, ''); } var images = document.querySelectorAll('.image'); var finalArray = {}; for ( var i=0; i<images.length; i++ ) { //I just filled in array. Depending on what you're grabbing, you may want to fill //This with objects instead with text to identify each image. finalArray.push(getDataFromDiv(images[i])); } return finalArray;https://stackoverflow.com/questions/30833290/fetching-images-with-javascriptresponse-in-cefbrowser-without-downloading-twice
相關文章
相關標籤/搜索