【发布时间】:2012-01-24 15:35:02
【问题描述】:
如果我的图像是这样的:<img src="picture.png" style="max-width:100px">,我如何从 javascript 中获取原始的、未缩放的图像大小?
我找到了我的答案,你可以使用img.naturalWidth得到原来的宽度
var img = document.getElementsByTagName("img")[0];
img.onload=function(){
console.log("Width",img.naturalWidth);
console.log("Height",img.naturalHeight);
}
【问题讨论】:
-
@bugster 我们如何实现这个以获取网站中缩放图像的原始大小?如果无法访问该网站,那么如何获取原始图像呢?考虑到原始图片 url 是一个公共链接。
标签: javascript