在js中获取上传图片的宽度和高度

Html:

1 <input type="file" id="MapUploadTd" onchange="getMapPictureSize(this.files[0])"/>

Js:

 1 var mapPictureSize = [];
 2 
 3 function getMapPictureSize(file) {
 4     var reader = new FileReader;
 5     reader.onload = function (evt) {
 6         var image = new Image();
 7         image.onload = function () {
 8             mapPictureSize[0] = this.width + "";
 9             mapPictureSize[1] = this.height + "";
10             console.log(mapPictureSize);
11         };
12         image.src = evt.target.result;
13     };
14     reader.readAsDataURL(file);
15 }

 

posted @ 2018-03-15 08:41  波兰火箭名宿  阅读(306)  评论(0编辑  收藏  举报