首页 > 解决方案 > 是否可以使用 ng-file-upload 读取图像的地理位置?

问题描述

我想知道,是否可以使用 ng-file-upload 库读取附加到图像文件的 Exif 元数据以读取地理位置。

有一些选项(例如 ngf-fix-orientation)可以使用 Exif 对象的元数据。但是,选择文件后,它不再包含任何 exif 信息。

我试过了:

ngf-before-model-change="beforeChange($files)"

和:

$scope.beforeChange = function(files){ console.log('BeforeChangefiles', files); };

结果如下:

0: File name: "IMG_5277.JPG" lastModified: 1559123113000 lastModifiedDate: Wed May 29 2019 11:45:13 GMT+0200 (Mitteleuropäische Sommerzeit) {} webkitRelativePath: "" size: 3741545 type: "image/jpeg" $ngfBlobUrl: "blob:http://localhost/630d0c34-07a1-4f41-81fd-e2cf021cbf65" $ngfWidth: 4032 $ngfHeight: 3024

此时 Exif 信息似乎已经丢失。

是否有可能在 exif 信息丢失之前访问它?

如果没有,推荐哪些解决方法?

标签: angularjsgeolocationexifng-file-upload

解决方案


JPEG 可能包含嵌入的 EXIF 段,其中可能包含 GPS 坐标。它们很容易提取。尽管我不推荐 exif-js,因为它已经多年无人维护,存在没有人回应的错误和堆积问题。

我会推荐exifr,它也可以很好地将 GPS 转换为简单值(以原始形式存储在 4 个单独的标签中)

// fancy async syntax
let {latitude, longitude} = await exifr.gps('./myimage.jpg')

// older promise syntax
exifr.gps(arrayBuffer).then(gps => {
  console.log(gps.latitude, gps.longitude)
})

输入可以是任何东西。URL、ArrayBuffer、Blob 等...


推荐阅读