I only have a URL to an image. I need to determine the height and width of this image using only JavaScript. The image cannot be visible to the user on the page. How can I get its dimensions?
You can also right-click on an image & choose properties from the drop-down menu. A new window will appear with several tabs. You'll click the details tab, and there you'll find you image size and dimensions.
Answer: Use the JavaScript clientWidth property You can simply use the JavaScript clientWidth property to get the current width and height of an image. This property will round the value to an integer.
var img = new Image(); img.onload = function(){ var height = img.height; var width = img.width; // code here to use the dimensions } img.src = url;
Make a new Image
var img = new Image();
Set the src
img.src = your_src
Get the width
and the height
//img.width //img.height
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With