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