Recover Picture Data on Local Disk:
For browsers that support HTML5/CSS3, it is possible according to the following code:
HTML:
<input type="file" id="choose" multiple="multiple" />
<br>
<div id="uploadPreview"></div>
Javascript:
// var url = window.URL || window.webkitURL; // alternate use
function readImage(file) {
var reader = new FileReader();
var image = new Image();
reader.readAsDataURL(file);
reader.onload = function(_file) {
image.src = _file.target.result; // url.createObjectURL(file);
image.onload = function() {
var w = this.width,
h = this.height,
t = file.type, // ext only: // file.type.split('/')[1],
n = file.name,
s = ~~(file.size/1024) +'KB';
$('#uploadPreview').append('<img src="'+ this.src +'"> '+w+'x'+h+' '+s+' '+t+' '+n+'<br>');
};
image.onerror= function() {
alert('Invalid file type: '+ file.type);
};
};
}
$("#choose").change(function (e) {
if(this.disabled) return alert('File upload not supported!');
var F = this.files;
if(F && F[0]) for(var i=0; i<F.length; i++) readImage( F[i] );
});
The line s = ~~(file.size/1024) +'KB';
gives you the size in bytes.
Look at this link for a demo.
I used it as a reference that answer stackoverflow.
Recover image data loaded from a URL:
Below is shown a simple example that shows properties of an image recovered from a URL without showing the size:
var img = new Image();
img.onload = function() {
alert(this.width + 'x' + this.height);
}
img.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';
This answer is also taken from a link stackoverflow.
According to this link of stackoverflow in English, it is not possible to recover the size of an image on the page, via javascript, only via server side. Note that the answer was marked as correct.
If the image is not in your domain is to give "problem" of cross Domain request same. Otherwise, we would have serious security issues - but note that some servers allow for cross-domain requests in some cases. If the image is in the same domain then it is easy to access the image. I hope that, for this case, you get a good answer here ;)
– Oralista de Sistemas