Sometimes, we want to determine image file size and dimensions via JavaScript.
In this article, we’ll look at how to determine image file size and dimensions via JavaScript.
How to determine image file size and dimensions via JavaScript?
To determine image file size and dimensions via JavaScript, we use the clientWidth
and clientHeight
properties.
For instance, we write
const img = document.getElementById("imageId");
const width = img.clientWidth;
const height = img.clientHeight;
to select the img element with getElementById
.
We get the width with the clientWidth
property and the height with the clientHeight
property.
Conclusion
To determine image file size and dimensions via JavaScript, we use the clientWidth
and clientHeight
properties.