JavaScript:获取图片尺寸 [英] JavaScript: Get image dimensions
本文介绍了JavaScript:获取图片尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只有一张图片的网址。我需要仅使用JavaScript来确定此图像的高度和宽度。该图像对于页面上的用户不可见。我怎样才能得到它的尺寸?
img.onload = function(){
var height = img.height;
var width = img.width;
//代码使用尺寸
}
img.src = url;
I only have a URL to an image. I need to determine the height and width of this image using only JavaScript. The image cannot be visible to the user on the page. How can I get its dimensions?
解决方案
var img = new Image();
img.onload = function(){
var height = img.height;
var width = img.width;
// code here to use the dimensions
}
img.src = url;
这篇关于JavaScript:获取图片尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文