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

Posted 明镜止水

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在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 }

 

以上是关于在js中获取上传图片的宽度和高度的主要内容,如果未能解决你的问题,请参考以下文章