我需要一个 JQuery 函数,它返回从输入类型文件中挑选的图像的高度和宽度。 我在Stackoverflow上找到了这个函数:
function getImageWidth(elemento){
$.fileImmagine = elemento;
var fr = new FileReader;
// file is loaded
fr.onload = function() {
var img = new Image;
img.onload = function() {
alert(img.width);
};
// is the data URL because called with
img.src = fr.result; readAsDataURL
};
// I'm using a <input type="file"> for demonstrating
fr.readAsDataURL($($.fileImmagine)[0].files[0]);
}
我不明白如何编辑此功能,以便将alert(img.width)
转换为return img.width
。
我怎样才能告诉&#34;仅在加载图像后才返回图像宽度的功能?
提前谢谢