Source Code: (back to article)
<!DOCTYPE html>
<html>
<head>
<title>Title of the Document</title>
</head>
<body>
<div>Click on img to see the result</div>
<script>
let img = document.createElement('img');
img.id = 'imgId';
img.src = '/uploads/media/default/0001/05/e9f3899d915c17845be51e839d5ba238f0404b07.png';
document.body.appendChild(img);
img.addEventListener("click", imgSize);
function imgSize() {
let myImg = document.querySelector("#imgId");
let realWidth = myImg.naturalWidth;
let realHeight = myImg.naturalHeight;
alert("Original width=" + realWidth + ", " + "Original height=" + realHeight);
}
</script>
</body>
</html>