繁体   English   中英

使用Javascript从图片中获取宽度和高度

[英]Getting width and height from a picture using Javascript

如何使用 Javascript 从存储在目录中的图片获取宽度和高度?

从网络浏览器:

<!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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM