vue使用exif獲取圖片經(jīng)緯度的示例代碼
我上一篇文章寫了怎么壓縮圖片和旋轉(zhuǎn)。這篇寫一下怎么看圖片的經(jīng)緯度
注意!??!
只有原圖有大量的元數(shù)據(jù)信息。通過拍照軟件如:b612等,拍攝的照片是軟件處理過的,所以一定要使用原圖來擦查詢
下面貼以下代碼。
<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;
//去獲取拍照時(shí)的信息,解決拍出來的照片旋轉(zhuǎn)問題
self.EXIF.getData(file, function() {
Orientation = self.EXIF.getTag(this, 'Orientation');
});
// 看支持不支持FileReader
if (!file || !window.FileReader) return;
if (/^image/.test(file.type)) {
// 創(chuàng)建一個(gè)reader
let reader = new FileReader();
// 將圖片2將轉(zhuǎn)成 base64 格式
reader.readAsDataURL(file);
// 讀取成功后的回調(diào)
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('我進(jìn)來了', direction, Longitude, Latitude);
console.log('allMetaData', allMetaData);
//接口 axios
// });
}
}
};
</script>
這個(gè)功能是下載的exif.js文件,也可以通過npm安裝依賴。不過都要掛在到原型鏈上。
以上就是vue使用exif獲取圖片經(jīng)緯度的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于vue 獲取圖片經(jīng)緯度的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
vue?demi支持sfc方式的vue2vue3通用庫開發(fā)詳解
這篇文章主要為大家介紹了vue?demi支持sfc方式的vue2vue3通用庫開發(fā)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08
vue3+vite項(xiàng)目中按需引入vant報(bào)錯(cuò):Failed?to?resolve?import的解決方案
最近在vue項(xiàng)目中引入vant的時(shí)候發(fā)現(xiàn)報(bào)錯(cuò)了,經(jīng)過嘗試發(fā)現(xiàn)了問題,現(xiàn)將完整引入流程提供給大家參考,下面這篇文章主要給大家介紹了關(guān)于vue3+vite項(xiàng)目中按需引入vant報(bào)錯(cuò):Failed?to?resolve?import的解決方案,需要的朋友可以參考下2022-12-12
vue中給el-radio添加tooltip并實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)方式
這篇文章主要介紹了vue中給el-radio添加tooltip并實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
Vue3解決Mockjs引入后并訪問404(Not Found) 的頁面報(bào)錯(cuò)問題
mock.js:是一款模擬數(shù)據(jù)生成器,可以生成隨機(jī)數(shù)據(jù),攔截 Ajax 請求,使用mockjs模擬后端接口,可隨機(jī)生成所需數(shù)據(jù),模擬對數(shù)據(jù)的增刪改查,本文給大家介紹了Vue3解決Mockjs引入后并訪問404(Not Found) 的頁面報(bào)錯(cuò)問題,需要的朋友可以參考下2025-04-04
Vue3與pywebview實(shí)現(xiàn)獲取本地文件夾的絕對路徑
這篇文章主要為大家詳細(xì)介紹了Vue3如何結(jié)合pywebview實(shí)現(xiàn)獲取本地文件夾的絕對路徑,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2024-11-11

