Skip to content

Instantly share code, notes, and snippets.

@alili
Created November 19, 2015 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alili/b751db940e501feeaa42 to your computer and use it in GitHub Desktop.
Save alili/b751db940e501feeaa42 to your computer and use it in GitHub Desktop.
判断上传图片像素值
var imageSize = false
var inputElement = document.getElementById("input");
inputElement.addEventListener("change", handleFiles, false);
function handleFiles() {
var fr = new FileReader;
fr.onload = function() { // file is loaded
var img = new Image;
img.onload = function() {
if(img.width<330 || img.height<185){
alert("请提供规定尺寸的图片")
inputElement.value = ""
}
else{
imageSize = true;
}
};
img.src = fr.result; // is the data URL because called with readAsDataURL
};
fr.readAsDataURL(this.files[0]); // I'm using a <input type="file"> for demonstrating
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment