1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
function checkResolution(id, width, height) {
var obj = document.getElementById(id);
var url, image;
if (obj.files && obj.files[0]) {
if (window.navigator.userAgent.indexOf( "MSIE" ) >= 1) {
obj.select();
url = document.selection.createRange().text;
}
url = window.URL.createObjectURL(obj.files[0]);
} else {
url = obj.value;
url = "file:///" + url;
}
image = new Image();
image.src = url;
return image.onload = function () {
setTimeout( function () {
if (image.width != width || image.height != height) {
alert(id + "上传的尺寸为:" + image.width + "*" + image.height
+ ",应上传:" + width + "*" + height);
return false ;
}
return true ;
}, 1);
};
}
|
Copy after login
The above is the detailed content of js method to verify image size. For more information, please follow other related articles on the PHP Chinese website!