summaryrefslogtreecommitdiff
path: root/modules/exif/lib/makers/gps.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/exif/lib/makers/gps.php')
-rw-r--r--modules/exif/lib/makers/gps.php128
1 files changed, 48 insertions, 80 deletions
diff --git a/modules/exif/lib/makers/gps.php b/modules/exif/lib/makers/gps.php
index 9a6ab137..462aae68 100644
--- a/modules/exif/lib/makers/gps.php
+++ b/modules/exif/lib/makers/gps.php
@@ -73,102 +73,65 @@ function lookup_GPS_tag($tag) {
}
//=================
-// Formats a rational number
-//====================================================================
-function GPSRational($data, $intel) {
-
- if($intel==1) $top = hexdec(substr($data,8,8)); //intel stores them bottom-top
- else $top = hexdec(substr($data,0,8)); //motorola stores them top-bottom
-
- if($intel==1) $bottom = hexdec(substr($data,0,8)); //intel stores them bottom-top
- else $bottom = hexdec(substr($data,8,8)); //motorola stores them top-bottom
-
- if($bottom!=0) $data=$top/$bottom;
- else if($top==0) $data = 0;
- else $data=$top."/".$bottom;
-
- return $data;
-}
-//=================
// Formats Data for the data type
//====================================================================
function formatGPSData($type,$tag,$intel,$data) {
if($type=="ASCII") {
- if($tag=="0001" || $tag=="0003"){ // Latitude Reference, Longitude Reference
- $data = ($data{1} == $data{2} && $data{1} == $data{3}) ? $data{0} : $data;
- }
-
+ if($tag=="0001" || $tag=="0003"){ // Latitude Reference, Longitude Reference
+ $data = ($data{1} == $data{2} && $data{1} == $data{3}) ? $data{0} : $data;
+ }
+
} else if($type=="URATIONAL" || $type=="SRATIONAL") {
- $data = bin2hex($data);
- if($intel==1) $data = intel2Moto($data);
-
- if($intel==1) $top = hexdec(substr($data,8,8)); //intel stores them bottom-top
- else $top = hexdec(substr($data,0,8)); //motorola stores them top-bottom
-
- if($intel==1) $bottom = hexdec(substr($data,0,8)); //intel stores them bottom-top
- else $bottom = hexdec(substr($data,8,8)); //motorola stores them top-bottom
-
- if($type=="SRATIONAL" && $top>2147483647) $top = $top - 4294967296; //this makes the number signed instead of unsigned
-
- if($tag=="0002" || $tag=="0004") { //Latitude, Longitude
-
- if($intel==1){
- $seconds = GPSRational(substr($data,0,16),$intel);
- $hour = GPSRational(substr($data,32,16),$intel);
- } else {
- $hour= GPSRational(substr($data,0,16),$intel);
- $seconds = GPSRational(substr($data,32,16),$intel);
+ if($tag=="0002" || $tag=="0004" || $tag=='0007') { //Latitude, Longitude, Time
+ $datum = array();
+ for ($i=0;$i<strlen($data);$i=$i+8) {
+ array_push($datum,substr($data, $i, 8));
+ }
+ $hour = unRational($datum[0],$type,$intel);
+ $minutes = unRational($datum[1],$type,$intel);
+ $seconds = unRational($datum[2],$type,$intel);
+ if($tag=="0007") { //Time
+ $data = $hour.":".$minutes.":".$seconds;
+ } else {
+ $data = $hour+$minutes/60+$seconds/3600;
}
- $minutes = GPSRational(substr($data,16,16),$intel);
-
- $data = $hour+$minutes/60+$seconds/3600;
- } else if($tag=="0007") { //Time
- $seconds = GPSRational(substr($data,0,16),$intel);
- $minutes = GPSRational(substr($data,16,16),$intel);
- $hour = GPSRational(substr($data,32,16),$intel);
-
- $data = $hour.":".$minutes.":".$seconds;
} else {
- if($bottom!=0) $data=$top/$bottom;
- else if($top==0) $data = 0;
- else $data=$top."/".$bottom;
-
- if($tag=="0006"){
- $data .= 'm';
- }
+ $data = unRational($data,$type,$intel);
+
+ if($tag=="0006"){
+ $data .= 'm';
+ }
}
} else if($type=="USHORT" || $type=="SSHORT" || $type=="ULONG" || $type=="SLONG" || $type=="FLOAT" || $type=="DOUBLE") {
- $data = bin2hex($data);
- if($intel==1) $data = intel2Moto($data);
- $data=hexdec($data);
-
-
+ $data = rational($data,$type,$intel);
+
+
} else if($type=="UNDEFINED") {
-
-
-
+
+
+
} else if($type=="UBYTE") {
$data = bin2hex($data);
if($intel==1) $num = intel2Moto($data);
if($tag=="0000") { // VersionID
- $data = hexdec(substr($data,0,2)) .
+ $data = hexdec(substr($data,0,2)) .
".". hexdec(substr($data,2,2)) .
".". hexdec(substr($data,4,2)) .
".". hexdec(substr($data,6,2));
- } else if($tag=="0005"){ // Altitude Reference
- if($data == "00000000"){ $data = 'Above Sea Level'; }
- else if($data == "01000000"){ $data = 'Below Sea Level'; }
- }
-
+ } else if($tag=="0005"){ // Altitude Reference
+ if($data == "00000000"){ $data = '+'; }
+ else if($data == "01000000"){ $data = '-'; }
+ }
+
} else {
$data = bin2hex($data);
if($intel==1) $data = intel2Moto($data);
}
-
+
return $data;
}
@@ -220,21 +183,26 @@ function parseGPS($block,&$result,$offset,$seek, $globalOffset) {
//4 byte value or pointer to value if larger than 4 bytes
$value = substr($block,$place,4);$place+=4;
-
if($bytesofdata<=4) {
$data = $value;
} else {
- $value = bin2hex($value);
- if($intel==1) $value = intel2Moto($value);
-
- $v = fseek($seek,$globalOffset+hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file
- if($v==0) {
- $data = fread($seek, $bytesofdata);
- } else if($v==-1) {
+ if (strpos('unknown',$tag_name) !== false || $bytesofdata > 1024) {
$result['Errors'] = $result['Errors']++;
+ $data = '';
+ $type = 'ASCII';
+ } else {
+ $value = bin2hex($value);
+ if($intel==1) $value = intel2Moto($value);
+ $v = fseek($seek,$globalOffset+hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file
+ if($v==0) {
+ $data = fread($seek, $bytesofdata);
+ } else {
+ $result['Errors'] = $result['Errors']++;
+ $data = '';
+ $type = 'ASCII';
+ }
}
}
-
if($result['VerboseOutput']==1) {
$result['GPS'][$tag_name] = formatGPSData($type,$tag,$intel,$data);
$result['GPS'][$tag_name."_Verbose"]['RawData'] = bin2hex($data);