js获取图片文件宽度和高度
这里利用FileReader对象来获取图片宽高。
代码如下
1 2 3 4 5 6 7 8 9 10 11
| const reader = new FileReader() // 获取base64格式字符串文件内容 reader.readAsDataURL(file) reader.onload = function(data) { const img = new Image() img.src = data.target.result let that = this img.onload = function() { console.log(this.width, this.height) } }
|
demo
https://jsbin.com/xalukapolu/edit?html,console,output
参考
https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader