Skip to content

JavaScript 获取图片宽高

Published: at 10:24 AMSuggest Changes

记一下获取图片宽高的方法

function getMeta(url) {
  var img = new Image();
  img.onload = function () {
    let { width, height } = img;
    console.log('{width, height} :>> ', { width, height });
  };
  img.src = url;
}
getMeta("https://www.xxxx.com/images.png")


Previous Post
JavaScript 字符串执行代码
Next Post
深入理解 CSS 中的块格式化上下文 (BFC)