import EXIF from 'exif-js'
http://code.ciaoca.com/javascript/exif-js/ 文档
EXIF.getData(document.getElementById('imgElement'), function(){
EXIF.getAllTags(this); 全部属性
EXIF.getTag(this, 'Orientation'); 某个属性
});
经纬度
const imgLon = EXIF.getTag(this, 'GPSLongitude')
const imgLat = EXIF.getTag(this, 'GPSLatitude')
//计算出经纬度并保留6为小数
const lon = (imgLon[0] + imgLon[1] / 60 + imgLon[2] / 60 / 60).toFixed(6)
const lat = (imgLat[0] + imgLat[1] / 60 + imgLat[2] / 60 / 60).toFixed(6)
https://blog.itsse.cn/904.html 配合高德定位
2023-1-20 更新
uniapp、小程序 使用问题
选择图片的时候 exif(图片信息)就是丢失的,这个是微信的限制 后面别看了。折腾了半天才发问题
var myexif = require('./myexif.js');
getImage() {
let _this = this
uni.chooseImage({
count: 1,
sizeType: ['original'],
sourceType: ['album'],
success: (res) => {
console.log(res);
const filePath = res.tempFilePaths[0];
_this.setBuffer(filePath)
}
})
},
setBuffer(filePath) {
let _this = this
uni.getFileSystemManager().readFile({
filePath,
success: (res) => {
console.log(res);
var r = myexif.handleBinaryFile(res.data);
console.log(_this.imageData );
console.log(r);
}
})
}
https://ext.dcloud.net.cn/plugin?id=4183
import {getImageData,getFloatLocationByExif} from './izExif.js'
getImageData(filePath).then(res=>{
console.log(res)
console.log(getFloatLocationByExif(res.exif))
}).catch(e=>{
console.log(e)
})