Last updated on February 14th, 2022 at 01:16 pm

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 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);
<img src="1.jpg" id="demoImg" />
<button onclick="getImgSize(document.getElementById('demoImg').src);" value="Click Me">

Leave a Reply

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