这篇文章给大家介绍怎么在vue中利用exif对图片信息中的经纬度进行获取,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
实现方法如下:
<template>
<div>
<input type="file" id="upload" accept="image" @change="upload" />
<span>{{textData}}</span>
</div>
</template>
<script>
export default {
data() {
return {
picValue: {},
headerImage: '',
textData:''
};
},
components: {},
methods: {
upload(e) {
console.log(e);
let files = e.target.files || e.dataTransfer.files;
if (!files.length) return;
this.picValue = files[0];
this.imgPreview(this.picValue);
},
imgPreview(file) {
let self = this;
let Orientation;
//去获取拍照时的信息,解决拍出来的照片旋转问题
self.EXIF.getData(file, function() {
Orientation = self.EXIF.getTag(this, 'Orientation');
});
// 看支持不支持FileReader
if (!file || !window.FileReader) return;
if (/^image/.test(file.type)) {
// 创建一个reader
let reader = new FileReader();
// 将图片2将转成 base64 格式
reader.readAsDataURL(file);
// 读取成功后的回调
reader.onloadend = function() {
let result = this.result;
let img = new Image();
img.src = result;
self.postImg(file);
};
}
},
postImg(val) {
//这里写接口
let self = this;
// document.getElementById('upload')
// this.EXIF.getData(val, function(r) {
let r = this.EXIF.getAllTags(val);
const allMetaData = r;
let direction;
if (allMetaData.GPSImgDirection) {
const directionArry = allMetaData.GPSImgDirection; // 方位角
direction = directionArry.numerator / directionArry.denominator;
}
let Longitude;
if (allMetaData.GPSLongitude) {
const LongitudeArry = allMetaData.GPSLongitude;
const longLongitude =
LongitudeArry[0].numerator / LongitudeArry[0].denominator +
LongitudeArry[1].numerator / LongitudeArry[1].denominator / 60 +
LongitudeArry[2].numerator / LongitudeArry[2].denominator / 3600;
Longitude = longLongitude.toFixed(8);
}
let Latitude;
if (allMetaData.GPSLatitude) {
const LatitudeArry = allMetaData.GPSLatitude;
const longLatitude =
LatitudeArry[0].numerator / LatitudeArry[0].denominator +
LatitudeArry[1].numerator / LatitudeArry[1].denominator / 60 +
LatitudeArry[2].numerator / LatitudeArry[2].denominator / 3600;
Latitude = longLatitude.toFixed(8);
}
self.textData = '我是Longitude' + Longitude + ' ====== '+"我是Latitude" + Latitude
console.log('我进来了', direction, Longitude, Latitude);
console.log('allMetaData', allMetaData);
//接口 axios
// });
}
}
};
</script>
这个功能是下载的exif.js文件,也可以通过npm安装依赖。不过都要挂在到原型链上。
关于怎么在vue中利用exif对图片信息中的经纬度进行获取就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。