Read Exif Data in React

huangapple go评论83阅读模式
英文:

Read Exif Data in React

问题

我正在尝试构建一个工具,用户可以为了SEO目的对他们的照片进行地理标记。我有一个带有地图的React应用程序,它会返回所需的坐标,它有两个表单组件。一个用于更改图像的EXIF GPS数据,另一个用于浏览并上传图像。我已经将大部分工作做好了,但我遇到的问题是我需要找到一种方法来返回图像的GPS数据。我找到了很多可以工作的JavaScript库,但似乎无法在我的React组件中使其正常工作。

需要注意的是,我可以访问文件路径和图像。我也可以返回一个图像对象,我只需要一个工具或方法来返回或显示Exif数据,并能够覆盖它。如果还没有这样的工具,如果有的话,请指导我如何构建这个工具。

英文:

I am trying to build this tool where a user can geotag their photos for SEO purposes. I have a react app with a map that will return the desired coordinates and it has 2 forms components. 1 that will change the EXIF GPS data for the image and a browser and upload images. I have most of it working the problem I am running into is I need to find a way to return the GPS data of an image I have found plenty of js libraries that will work but I can't seem to get it to work in my React components.

Something to now I have access to the file path and the image. I can return an image object as well I just need a tool or away to return or display the Exif data and be able to overwrite it. There may not be a tool yet if not guide in the direction to maybe build that tool.

答案1

得分: 2

there's a simple library for that called exifr.

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

or another way to write this:

exifr.gps(buffer, gps => console.log(gps.latitude, gps.longitude))

and to get the whole EXIF and not just GPS, there's exifr.parse()

exifr.parse(uin8array).then(...)

You can use pretty much anything as input (file path, Buffer, ArrayBuffer, Uint8Array, Blob, URL, and more). Unfortunately, it doesn't yet support writing exif back to the file.

英文:

there's a simple library for that called exifr.

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

or another ways to write this:

exifr.gps(buffer, gps => console.log(gps.latitude, gps.longitude))

and the get the whole EXIF and not just GPS, there's exifr.parse()

exifr.parse(uin8array).then(...)

You can use pretty much anything as input (file path, Buffer, ArrayBuffer, Uint8Array, Blob, URL, and more). Unfortunately it doesn't yet support writing exif back to the file.

huangapple
  • 本文由 发表于 2020年1月3日 22:46:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580568.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定