js 获取file控件选中图片的宽高

input file控件选中文件后,转为image对象就ok了

//首先你得先验证选择的是图片哦,使用后缀验证        
var file = $(e)[0].files[0];//选中的第一个文件 let url = window.URL || window.webkitURL; console.log(url.createObjectURL(file)); let img = new Image(); //手动创建一个Image对象 img.src = url.createObjectURL(file);//创建Image的对象的url img.onload = function () { console.log('height:' + this.height + '----' + this.width) }
原文地址:https://www.cnblogs.com/liuzheng0612/p/12896017.html