PHP extract GPS EXIF data
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]);
}
Issues extracting exif data for exif 2.3 using PHP Version 5.2.9
I also have a Fujifilm camera with the same problem, but I think I've found the solution, I've raised a PHP bug report here:
https://bugs.php.net/bug.php?id=66443
If you can compile PHP from source, increase the value of MAX_IFD_NESTING_LEVEL in the exif.c file. I raised it from 100 to 200 and it appears to have fixed the problem.
Mapping exif data to long/lat
You devide the minutes and seconds by 100, but well, you shouldn't:
$d = $deg + ((($min/60) + ($sec/3600))/100);
should be:
$d = $deg + (($min/60) + ($sec/3600));
one minute is 1/60 degree and a second is 1/60 minute.
for a more thorough answer, see here: PHP extract GPS EXIF data
PHP exif_read_data no longer extracts GPS location
This is most likely due to a regression from a security fix that was causing the ext/exif extension to stop parsing in case of an "unknown" format.
This should be fixed in the 7.x branches (7.0.10 and 7.1.0 Beta 1) should contain a proper fix for these, although it was not merged to the 5.x branches, it could likely find its way there.
If you want a patch (which should be fairly easy to convert into 5.x), then I committed it here:
http://git.php.net/?p=php-src.git;a=commit;h=aabcb5481d9e717df77192dab2894468b9fc63b4
Here is a little background on how ext/exif works and what went wrong:
Internally when we parse the exif data, it will read out the standard exif tags as provided by the spec, however certain formats, have certain custom tags. These are usually parsed too, however ext/exif is limited in the sense that we only (in stable branches including 7.1) support 6 formats with extended tags (the list for each format is baked into the extension). This is where the regression comes in. When parsing the EXIF data, it is done in the following order:
- Standard EXIF data
- Look for known formats for parsing custom tags, if a matching signature is found, then parse them
- Parse additional data, like thumbnail, GPS etc
The security fix caused a regression, because you could craft fake signatures and bypass this internally, which could cause invalid reads. The fix would then bail the parsing in case of a signature mismatch in the list of baked in signatures from formats we know, thus stopping to parse and not returning data like thumbnails, causing exif_thumbnail() to essentially not be usable for any but the 6 formats.
The fix currently in the 7.x branches, restores this behavior and simply continues to parse those additional tags, so those functions and other formats we do not directly support, will once again work.
Besides that, in 7.2, I have been adding support for Samsung, Panasonic and DJI specific tags, and I'm currently looking into Sony specific data too. We have a bug report at php.net which sparkled it all in case you are interested in looking more in depth with this: https://bugs.php.net/bug.php?id=72735. And should this patch not fix your issue, you are more than welcome to submit a bug report so we can look into resolving this.
I hope this was helpful to you, and thanks for helping to make PHP even greater!
PHP Convert Exif GPS data to Google friendly values
I found that same formula, and it didn't work for me either. What I finally figured out, and what worked for me, was:
function toDecimal($deg, $min, $sec, $hem)
{
$d = $deg + ((($min/60) + ($sec/3600))/100);
return ($hem=='S' || $hem=='W') ? $d*=-1 : $d;
}
Extracting EXIF data displaying 'Array'
It is, because it is an array.
print_r($val);
http://codepad.viper-7.com/PPJtsB
GPSTrack from exif
It is rational64u
(as used in latitudes and longitudes, and in many places in EXIF) so a float is represented by two integers, a numerator and a denominator.
To get the float, you just divide the two:
degree = numerator / denominator
so
degree = numerator / denominator = 116001 / 424 = 273.587264150943
Usual warning: carious computer languages will do an integer division if the two operand are integer, so you may need to cast them to floats before doing the division.
Related Topics
Woocommerce: Display Some Reviews Randomly on Home Page
PHP Foreach by Reference Causes Weird Glitch When Going Through Array of Objects
How to Access a PHP Object Attribute Having a Dollar Sign
Applied Coupons Disable Free Shipping Conditionally in Woocommerce
How to Remove the Leading Character from a String
How to Use Break or Continue Within for Loop in Twig Template
Make Switch Use === Comparison Not == Comparison in PHP
Generating a Screenshot of a Website Using Jquery
Downloading a File with a Different Name to the Stored Name
Performance in Pdo/Php/Mysql: Transaction Versus Direct Execution
Is PHP's 'Include' a Function or a Statement
Combine PHP Prepared Statments with Like
Convert Number to Letter with PHP
Resetting MySQL Root Password with Xampp on Localhost
Codeigniter: Best Way to Structure Partial Views