I want to preview images that the user wants to upload. I have tried to create a canvas for each image to make it easier to work with.
If I select multiple images only the final one shows when all images are meant to be show.
<input type="file" id="browseImages" multiple="multiple" accept="image/*">
<output id="list"></output>
document.getElementById('browseImages').addEventListener('change', handleFileSelect, true);
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var canvas = document.createElement('canvas');
canvas.width = 110;
canvas.height = 100;
var ctx = canvas.getContext("2d");
var img = new Image;
img.onload = function() {
ctx.drawImage(img, 0, 0, 100, 100);
}
img.src = window.URL.createObjectURL(f);
document.getElementById('list').appendChild(canvas);
window.URL.revokeObjectURL(f);
}
}