获取图片宽高
img = new Image(); img.src = URL.createObjectURL(file) img.onload = function(){ console.log(img.naturalWidth || img.width) }
URL.createObjectURL
可以把 input 选择的文件转换为一个 url。
- 我们使用 img 标签来加载图片。
- 获取图片宽高需要 onload 之后,才能获取。
获取 Exif 信息
使用的库是 exif-js。
提供了 JavaScript 读取图像的原始数据的功能扩展,例如:拍照方向、相机设备型号、拍摄时间、ISO 感光度、GPS 地理位置等数据。
使用方法
EXIF.getData(file, function(){ console.log('getData', this); // 这里面可以看到值,想要什么直接获取即可。 console.log('getAllTags', EXIF.getAllTags(this)); });
拍摄方向
正好前两天在看这方面的知识,也顺便贴一下。
图片Exif 信息中Orientation的理解和对此的处理