簡體   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