使用纯Javascript检查输入类型文件的图像分辨率

使用纯Javascript检查输入类型文件的图像分辨率,javascript,image,filereader,Javascript,Image,Filereader,我已经创建了一个type=file输入元素 <input type="file" id="input-id" accept="image/jpg" onchange="verifyFileUpload(event)"> 我需要使用纯Javascript检查文件分辨率是否为aXb。如何在verifyFileUpload(event)功能中执行此操作?请尝试以下方法 window.URL=window.URL | | window.webkitURL; 函数verifyFileU

我已经创建了一个
type=file
输入元素

<input type="file" id="input-id" accept="image/jpg" onchange="verifyFileUpload(event)">

我需要使用纯Javascript检查文件分辨率是否为
aXb
。如何在
verifyFileUpload(event)
功能中执行此操作?

请尝试以下方法

window.URL=window.URL | | window.webkitURL;
函数verifyFileUpload(e)
{
var file=document.getElementById(“输入id”);
如果(file&&file.files.length>0)
{
var img=新图像();
img.src=window.URL.createObjectURL(file.files[0]);
img.onload=函数()
{
var width=this.naturalWidth,
高度=这个。自然高度;
console.log(“图像宽度:”+宽度);
console.log(“图像高度:”+高度);
};
}
}
试试下面的方法

window.URL=window.URL | | window.webkitURL;
函数verifyFileUpload(e)
{
var file=document.getElementById(“输入id”);
如果(file&&file.files.length>0)
{
var img=新图像();
img.src=window.URL.createObjectURL(file.files[0]);
img.onload=函数()
{
var width=this.naturalWidth,
高度=这个。自然高度;
console.log(“图像宽度:”+宽度);
console.log(“图像高度:”+高度);
};
}
}

<代码> >代码>事件>目标。文件< /代码>返回所选文件。此问题的数据可重复副本有许多在线答案,即使在堆栈溢出时,请考虑在发布问题之前进行快速搜索。同样可能的复制<代码>事件>目标文件>代码>返回选择的文件。这个问题的数据副本有很多在线答案,即使在堆栈溢出时,也请考虑在发布问题之前进行快速搜索。也可能重复