I need to display the image size in kilobyte and the dimension (height, width) using javascript/jquery. I came across few similar posts, but none could help me. I have two set o
You can try like this
HTML
JQUERY
var _URL = window.URL || window.webkitURL;
function displayPreview(files) {
var img = new Image(),
fileSize = Math.round(files.size / 1024);
img.onload = function () {
var width = this.width,
height = this.height,
imgsrc = this.src;
doSomething(fileSize, width, height, imgsrc); //call function
};
img.src = _URL.createObjectURL(files);
}
// Do what you want in this function
function doSomething(size, width, height, imgsrc) {
$('#preview').append('');
alert("Size=" + size);
alert("Width=" + width + " height=" + height);
}
Both methods
Jsfiddle http://jsfiddle.net/code_snips/w4y75/ Jsfiddle http://jsfiddle.net/code_snips/w4y75/1/