js在前端获取在本地上传图片的尺寸

来源:互联网 发布:熊猫 知乎 编辑:程序博客网 时间:2024/05/21 11:03
var MyTest = document.getElementById("upload_img").files[0];
var reader = new FileReader();
reader.readAsDataURL(MyTest);
reader.onload = function(theFile) {
  var image = new Image();
  image.src = theFile.target.result;
    image.onload = function() {
     alert("图片的宽度为"+this.width+",长度为"+this.height);
    };

};


其中,id为“upload_img”的标签如下:

<input type="file" size="20" autocomplete="off" id="upload_img" name="Uploadfile">

转载自:https://www.cnblogs.com/longzhongren/p/5715628.html

原创粉丝点击