【问题标题】:Is it possible to read the geolocation of images using ng-file-upload?是否可以使用 ng-file-upload 读取图像的地理位置?
【发布时间】:2020-02-25 08:27:32
【问题描述】:

我想知道,是否可以使用 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 信息丢失之前访问它?

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

【问题讨论】:

    标签: angularjs geolocation exif ng-file-upload


    【解决方案1】:

    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 等...

    【讨论】:

    • 感谢使用 exifr 库的建议。我可以将文件 blob 传递给 exifr.gps(blob) 并读取地理位置数据。我的问题现在解决了。
    【解决方案2】:

    该库似乎无法检索您的 EXIF 元数据。有很多未解决的问题,但通常应该支持 (this one for example)。

    您可以尝试使用exif-js 检索您的图像 EXIF 元数据,然后再对它们进行进一步处理:

    EXIF.getData(yourImg, function() {
        var allMetaData = EXIF.getAllTags(this);
        var allMetaDataSpan = document.getElementById("allMetaDataSpan");
        allMetaDataSpan.innerHTML = JSON.stringify(allMetaData, null, "\t");
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-26
      • 1970-01-01
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多