PHP提取GPS EXIF数据 [英] PHP extract GPS EXIF data
问题描述
我想从使用php的图片中提取GPS EXIF标签。
我使用 exif_read_data()
返回所有标签+数据的数组:
<$ p $ [p] 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'不知道如何解释46/1 5403/100和0/1? 46可能是46°,但其余的尤其是0/1呢?
angle / 1 5403/100 0/1
这是什么结构?
如何将它们转换为标准(例如来自维基百科的46°56'48N 7°26'39E)?我想通过坐标到谷歌地图API来显示地图上的图片位置! 解决方案
根据 http://en.wikipedia.org/wiki/Geotagging ,([0 ] => 46/1 [1] => 5403/100 [2] => 0/1)应该表示46/1度,5403/100分钟,0/1秒,即46°54.03'0N。正常化的秒数为46°54'1.8N。
只要你没有得到负坐标(假设你得到N / S和E / W作为单独的坐标,您不应该有负坐标)。
//通过在GPS.GPSLatitude或GPS.GPSLongitude或以这种格式的东西
function getGps($ exifCoord)
{
$ degrees = count($ exifCoord)> 0? gps2Num($ exifCoord [0]):0;
$分钟= count($ exifCoord)> 1? gps2Num($ exifCoord [1]):0;
$ seconds = count($ exifCoord)> 2? gps2Num($ exifCoord [2]):0;
//标准化
$分钟+ = 60 *($ degrees - floor($ degrees));
$ degrees = floor($ degrees);
$秒+ = 60 *($分钟 - 楼层($分钟));
$分钟=楼层($分钟);
//额外的标准化,可能不需要,除非你得到奇怪的数据
if($ seconds> = 60)
{
$ minutes + = floor($秒/ 60.0);
$ seconds - = 60 * floor($ seconds / 60.0); ($分钟> = 60)
{
$ degrees + = floor($分钟/ 60.0);
}
$分钟 - = 60 *地板($分钟/ 60.0);
}
return array('degrees'=> $ degrees,'minutes'=> $ minutes,'seconds'=> $ seconds);
}
函数gps2Num($ coordPart)
{
$ parts = explode('/',$ coordPart);
if(count($ parts)< = 0)// jic
return 0;
if(count($ parts)== 1)
return $ parts [0];
$ b $返回floatval($ parts [0])/ floatval($ parts [1]);
}
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 !
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).
//Pass in GPS.GPSLatitude or GPS.GPSLongitude or something in that format
function getGps($exifCoord)
{
$degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
$minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
$seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
//normalize
$minutes += 60 * ($degrees - floor($degrees));
$degrees = floor($degrees);
$seconds += 60 * ($minutes - floor($minutes));
$minutes = floor($minutes);
//extra normalization, probably not necessary unless you get weird data
if($seconds >= 60)
{
$minutes += floor($seconds/60.0);
$seconds -= 60*floor($seconds/60.0);
}
if($minutes >= 60)
{
$degrees += floor($minutes/60.0);
$minutes -= 60*floor($minutes/60.0);
}
return array('degrees' => $degrees, 'minutes' => $minutes, 'seconds' => $seconds);
}
function gps2Num($coordPart)
{
$parts = explode('/', $coordPart);
if(count($parts) <= 0)// jic
return 0;
if(count($parts) == 1)
return $parts[0];
return floatval($parts[0]) / floatval($parts[1]);
}
这篇关于PHP提取GPS EXIF数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!