Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions main.inc.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Exiftool GPS
Version: 0.7
Version: 0.7a
Description: Uses command line exiftool to read exif GPS data. (Plugin based on Exiftool Keywords.)
Plugin URI: http://piwigo.org/ext/extension_view.php?eid=850
Author: ramack, plg
Expand All @@ -20,35 +20,40 @@ function eg_format_exif_data($exif, $filepath, $map)
$output = shell_exec('exiftool -json "'.$filepath.'"');
$metadata = json_decode($output, true);

foreach ($metadata as $key => $section) {
foreach ($section as $name => $val) {
if(substr( $name, 0, 3 ) === "GPS")
{
if($name === "GPSLatitude" or $name === "GPSLongitude")
{
/* convert to x/1 y/1 z/... format */
$p1 = explode("deg", $val);
$v1 = intval($p1[0]) . "/1";
$p2 = explode("'", $p1[1]);
$v2 = intval($p2[0]) . "/1";

$p3 = explode("\"", $p2[1]);
$v3 = intval($p3[0] * 10000) . "/10000";

$exif[$name] = array($v1, $v2, $v3);
}
else if($name === "GPSLatitudeRef" or $name === "GPSLongitudeRef")
{
$exif[$name] = substr($val, 0, 1);
$exif = array();
if(is_array($metadata)) {
foreach ($metadata as $key => $section) {
if(!is_array($section)) {
continue;
}
foreach ($section as $name => $val) {
if(substr( $name, 0, 3 ) === "GPS")
{
if($name === "GPSLatitude" or $name === "GPSLongitude")
{
/* convert to x/1 y/1 z/... format */
$p1 = explode("deg", $val);
$v1 = intval($p1[0]) . "/1";
$p2 = explode("'", $p1[1]);
$v2 = intval($p2[0]) . "/1";

$p3 = explode("\"", $p2[1]);
$v3 = intval($p3[0] * 10000) . "/10000";

$exif[$name] = array($v1, $v2, $v3);
}
else if($name === "GPSLatitudeRef" or $name === "GPSLongitudeRef")
{
$exif[$name] = substr($val, 0, 1);
}
else
{
$exif[$name] = $val;
}
}
else
{
$exif[$name] = $val;
}
}
}
}

return $exif;
}
?>