please tell me how to get image size of all images in the page using jquery or javascript
Asked
Active
Viewed 1.2k times
2
-
You want the total size summed up? each image separate? – The Scrum Meister Dec 29 '10 at 07:43
-
possible duplicate of [How to get image size (height & width) using JavaScript?](http://stackoverflow.com/questions/623172/how-to-get-image-size-height-width-using-javascript) – Anthony Hatzopoulos Oct 15 '14 at 14:28
3 Answers
4
The only size you can get is the visible size. clientWidth and clientHeight are two DOM properties which do this. Example:
var image = document.getElementById("id");
var width = image.clientWidth;
var height = image.clientHeight;
If you're using jQuery, you can simply use $.width and $.height:
var width = $("id").width();
var height = $("id").height();
So, to get the size of all images, loop them through:
$("img").each(function()
{
console.log(this.width());
console.log(this.height());
});
If you need the real size, please see this question Get the real width and height of an image with JavaScript? (in Safari/Chrome)
-
I have a form to upload an image, is there any way to get image dimensions on the client side before I process it on server side. – SIFE Nov 14 '12 at 00:15
-
@SIFE Yes, it is possible in newer browsers. Please ask this in a new question. – alexn Nov 14 '12 at 06:18
-
See my [question](http://stackoverflow.com/questions/13390167/how-to-get-image-dimensions-on-the-client-side) pls. stackoverflow must star thinking on url shortening service. – SIFE Nov 15 '12 at 01:18
2
$('img').each(function() {
$(this).width(); // current image's width
$(this).height(); // current image's height
});

Tatu Ulmanen
- 123,288
- 34
- 187
- 185