Last updated on May 16th, 2016 at 03:21 pm

VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)

Get Image Size Using Javascript

I am using getImgSize() function here which will in turn get the height and width of the image in question.
Image source is defined with an ID named demoImg from which we get all the details of the image. Size of the image will be width * height.

<script language="JavaScript">
function getImgSize(imgSrc)
{var newImg = new Image();
newImg.src = imgSrc;
var height = newImg.height;
var width = newImg.width;
alert ('The image size is '+width+'*'+height);
}</script>
<img src="1.jpg" id="demoImg" />
<button onclick="getImgSize(document.getElementById('demoImg').src);" value="Click Me">
</button>
VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)

Leave a Reply

Your email address will not be published. Required fields are marked *