Created
November 19, 2015 08:23
-
-
Save alili/b751db940e501feeaa42 to your computer and use it in GitHub Desktop.
判断上传图片像素值
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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