PHP提取GPS EXIF数据
我想使用 php 从图片中提取 GPS EXIF 标签。 我正在使用 exif_read_data()
返回所有标签 + 数据的数组:
GPS.GPSLatitudeRef: N
GPS.GPSLatitude:Array ( [0] => 46/1 [1] => 5403/100 [2] => 0/1 )
GPS.GPSLongitudeRef: E
GPS.GPSLongitude:Array ( [0] => 7/1 [1] => 880/100 [2] => 0/1 )
GPS.GPSAltitudeRef:
GPS.GPSAltitude: 634/1
我不知道如何解释 46/1 5403/100 和 0/1 ? 46 可能是 46° 但其余的尤其是 0/1 呢?
angle/1 5403/100 0/1
这个结构是关于什么的?
如何将它们转换为“标准”(例如维基百科中的 46°56′48″N 7°26′39″E)?我想将这些坐标传递给谷歌地图 API 以在地图上显示图片位置!
I would like to extract the GPS EXIF tag from pictures using php.
I'm using the exif_read_data()
that returns a array of all tags + data :
GPS.GPSLatitudeRef: N
GPS.GPSLatitude:Array ( [0] => 46/1 [1] => 5403/100 [2] => 0/1 )
GPS.GPSLongitudeRef: E
GPS.GPSLongitude:Array ( [0] => 7/1 [1] => 880/100 [2] => 0/1 )
GPS.GPSAltitudeRef:
GPS.GPSAltitude: 634/1
I don't know how to interpret 46/1 5403/100 and 0/1 ? 46 might be 46° but what about the rest especially 0/1 ?
angle/1 5403/100 0/1
What is this structure about ?
How to convert them to "standard" ones (like 46°56′48″N 7°26′39″E from wikipedia) ? I would like to pass thoses coordinates to the google maps api to display the pictures positions on a map !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
这是我修改后的版本。其他的对我不起作用。它将为您提供 GPS 坐标的十进制版本。
处理 EXIF 数据的代码:
以这种格式打印:
以下是函数:
This is my modified version. The other ones didn't work for me. It will give you the decimal versions of the GPS coordinates.
The code to process the EXIF data:
Prints out in this format:
Here are the functions:
这是 Gerald Kaszuba 代码的重构版本(目前最广泛接受的答案)。结果应该是相同的,但我进行了一些微观优化,并将两个独立的功能合并为一个。在我的基准测试中,该版本将运行时间缩短了约 5 微秒,这对于大多数应用程序来说可能可以忽略不计,但对于涉及大量重复计算的应用程序可能很有用。
This is a refactored version of Gerald Kaszuba's code (currently the most widely accepted answer). The result should be identical, but I've made several micro-optimizations and combined the two separate functions into one. In my benchmark testing, this version shaved about 5 microseconds off the runtime, which is probably negligible for most applications, but might be useful for applications which involve a large number of repeated calculations.
根据 http://en.wikipedia.org/wiki/Geotagging,
( [ 0] => 46/1 [1] => 5403/100 [2] => 0/1 )
应该表示 46/1 度,5403/100 分钟,0/1 秒,即 46 °54.03′0″N。将秒归一化后得到 46°54′1.8″N。只要您没有获得负坐标,下面的代码就应该有效(假设您将 N/S 和 E/W 作为单独的坐标,那么您不应该获得负坐标)。如果有错误请告诉我(我目前手头没有 PHP 环境)。
According to http://en.wikipedia.org/wiki/Geotagging,
( [0] => 46/1 [1] => 5403/100 [2] => 0/1 )
should mean 46/1 degrees, 5403/100 minutes, 0/1 seconds, i.e. 46°54.03′0″N. Normalizing the seconds gives 46°54′1.8″N.This code below should work, as long as you don't get negative coordinates (given that you get N/S and E/W as a separate coordinate, you shouldn't ever have negative coordinates). Let me know if there is a bug (I don't have a PHP environment handy at the moment).
这是一个老问题,但感觉它可以使用更雄辩的解决方案(OOP 方法和 lambda 来处理小数部分)
This is an old question but felt it could use a more eloquent solution (OOP approach and lambda to process the fractional parts)
我知道这个问题很久以前就被问过,但是我在谷歌搜索时遇到了它,并且这里提出的解决方案对我不起作用。因此,经过进一步搜索,这对我有用。
我把它放在这里,以便任何通过谷歌搜索来到这里的人都可以找到解决同一问题的不同方法:
I know this question has been asked a long time ago, but I came across it while searching in google and the solutions proposed here did not worked for me. So, after further searching, here is what worked for me.
I'm putting it here so that anybody who comes here through some googling, can find different approaches to solve the same problem:
我过去使用的代码类似于(实际上,它还检查数据是否模糊有效):
您还可以:
The code I've used in the past is something like (in reality, it also checks that the data is vaguely valid):
Where you also have:
要获取海拔高度值,可以使用以下 3 行:
To get the altitude value, you can use the following 3 lines:
如果您需要一个从 Imagick Exif 读取坐标的功能,我们就来吧,我希望它可以节省您的时间。在 PHP 7 下测试。
In case you need a function to read Coordinates from Imagick Exif here we go, I hope it saves you time. Tested under PHP 7.
我正在使用 Gerald Kaszuba 的修改版本,但它不准确。
所以我稍微改变一下公式。
从:
改为:
这对我有用。
I'm using the modified version from Gerald Kaszuba but it's not accurate.
so i change the formula a bit.
from:
changed to:
It works for me.
这是上面 @Gerald 发布的 PHP 代码的 javascript 端口。通过这种方式,您可以结合 dropzone.js 和 Javascript-Load-Image
This is a javascript port of the PHP-code posted @Gerald above. This way you can figure out the location of an image without ever uploading the image, in conjunction with libraries like dropzone.js and Javascript-Load-Image
短篇小说。
第一部分 N
留下等级
分钟乘以 60
将秒除以 100。
互相数着成绩、分、秒。
第二部分E
留下等级
分钟乘以 60
将秒除以 ...1000
互相计算成绩、分、秒
short story.
First part N
Leave the grade
multiply the minutes with 60
devide the seconds with 100.
count the grades,minuts and seconds with eachother.
Second part E
Leave the grade
multiply the minutes with 60
devide the seconds with ...1000
cöunt the grades, minutes and seconds with each other
我看到没有人提到这一点: https://pypi.python.org/pypi/LatLon /1.0.2
现在使用 Coordonates 对象你可以做你想做的事:
示例:(
如维基百科中的 46°56′48″N 7°26′39″E)
您必须从 ascii 进行转换,然后就完成了:
然后打印示例:
i have seen nobody mentioned this: https://pypi.python.org/pypi/LatLon/1.0.2
now using the Coordonates objecct you can do what you want:
Example:
(like 46°56′48″N 7°26′39″E from wikipedia)
You than have to convert from ascii, and you are done:
and than printing example: