I want to get the image size using javascript or jquery. something similar to imagesize().
Thanks Jean
I want to get the image size using javascript or jquery. something similar to imagesize().
Thanks Jean
Has already been asked and answered - How to get image size (height & width) using JavaScript?
var img = document.getElementById('imageid');
var width = img.clientWidth;
var height = img.clientHeight;
That depends. If the image already has width/height styles/attributes applied to it, you will not get the image's width/height, but you will get the resized dimensions. Here's a possible solution:
function getImageSize(img) {
var clone = img.clone();
clone.width("auto")
.height("auto")
.css("position", "absolute")
.css("left", -9999)
.css("top", -9999);
$(document.body).append(clone);
var width = clone.width();
var height = clone.height();
clone.remove();
return [width, height];
}
Untested, but it should work. However, if you're sure the image is not resized from css/html, there's no need for this complication and you can use what the others have said.
you can use .attr('width') and .attr('height') unless you mean size in bytes?
this wouldnt work if the img is being rescaled with css