I'm trying to get the size of an image along with other parameters during upload.
<script>
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 imagem = new Image();
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
imagem.src = e.target.result;
var span = document.createElement('span');
span.innerHTML = ['<img id="foto" class="materialboxed responsive-img" width="650" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
var output = [];
output.push('<li><strong>', '</strong> (', theFile.type || 'n/a', ') - ',
theFile.size, ' bytes -',imagem.onload = function() {
var height = this.height,
width = this.width;
alert(width+'x'+height);
return width+'x'+height+'oi';
},'</li>');
document.getElementById('list').insertBefore(span, null);
document.getElementById('list1').innerHTML = '<ul>' + output.join('') + '</ul>';
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('file').addEventListener('change', handleFileSelect, false);
</script>
I am not able to capture the value returned from the imagem.onload
function, however the value appears in alert
when I click to make the image preview with the dimension, with return
only giving undefined
. Where am I going wrong? I have tried to use variables to try to get the value, but it does not, however, alert
displays the value.