0

How can I get width and height from a picture stored in a directory using Javascript?

1 Answer 1

1

From a web browser:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Image Dimensions</title>
</head>

<body>
  <img id="myImage" src="image.png">

  <script>
  var img = document.getElementById("myImage");
  img.onload = function (event) {
    console.log(`natural: ${img.naturalWidth}, ${img.naturalHeight}`);
    console.log(`width,height: ${img.width}, ${img.height}`);
    console.log(`offset: ${img.offsetWidth}, ${img.offsetHeight}`);
  }
  </script>

</body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

Muchas gracias!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.