对又是我,天天都有新的需求。html
此次的需求是上传图片的时获取图片的宽高、设备、光圈等信息。前端
不用考虑服务端作,他们确定是不作。android
pc、android、ios 都支持了,如今就缺乏 web 这边上传的图片了。ios
废话不对说,上测试地址:https://www.lilnong.top/static/html/exif.htmlgit
img = new Image(); img.src = URL.createObjectURL(file) img.onload = function(){ console.log(img.naturalWidth || img.width) }
URL.createObjectURL
能够把 input 选择的文件转换为一个 url。使用的库是 exif-js。
提供了 JavaScript 读取图像的原始数据的功能扩展,例如:拍照方向、相机设备型号、拍摄时间、ISO 感光度、GPS 地理位置等数据。github
EXIF.getData(file, function(){ console.log('getData', this); // 这里面能够看到值,想要什么直接获取便可。 console.log('getAllTags', EXIF.getAllTags(this)); });
正好前两天在看这方面的知识,也顺便贴一下。web
图片Exif 信息中Orientation的理解和对此的处理微信