js 获取上传图片的宽度和高度的方法

 html代码:
  <input type="file"
       id='inputFile${index$}'
       name="uploadFile0"                                                        
    accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"
       style="display:none"                                                        
       onchange="getMapPictureSize(this, ${index$})"
       multiple/>


js代码:

function getMapPictureSize(that, index) {
    var curFile = that.files;

    var reader = new FileReader;
    reader.onload = function (evt) {
        //加载图片获取图片真实宽度和高度
        var image = new Image();
        image.onload = function () {
            $('#composeWidth_' + index).attr("value", this.width);
            $('#composeHeight_' + index).attr("value", this.height);
        };
        image.src = evt.target.result;
    };
    //先转换为图片之后,再获取宽度和高度
    reader.readAsDataURL(curFile[0]);
}

 

上一篇:P5709 【深基2.习6】Apples Prologue / 苹果和虫子


下一篇:Linux concurrency - 1.简介