input-file 图片上传尺寸验证

uploadimg.html




	
	Document
	


	


图片尺寸修改

uploadimg.js

var width,height;
function handleConLogo(files){

   for (var i = 0; i < files.length; i++) {
    var file = files[i];
    var reader = new FileReader();
    var ret = [];
    reader.onload = function(theFile) {
        var image = new Image();
        image.onload = function() {
            width=this.width; 
            height=this.height;
            if(width> 200 || height> 200){
                fill = false;
                alert("图片像素不符合,应小于200px*200px,建议重新上传!");
            }else{
                alert("图片格式符合要求!")
            }
        };
        image.src = theFile.target.result;
    }
    reader.readAsDataURL(file);
}
}
function handleConId_photo(files){

   for (var i = 0; i < files.length; i++) {
    var file = files[i];
    var reader = new FileReader();
    var ret = [];
    reader.onload = function(theFile) {
        var image = new Image();
        image.onload = function() {
            width=this.width; 
            height=this.height;
            if(width> 200 || height> 400){
                fill = false;
                alert("图片像素不符合,应小于200px*400px,建议重新上传!");
            }else{
                alert("图片格式符合要求!")
            }
        };
        image.src = theFile.target.result;
    }
    reader.readAsDataURL(file);
}
}


你可能感兴趣的:(js;html)