From 37d90e663ca75fdf441d449799fc94a5e467b4a7 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 7 Feb 2009 21:44:19 +0000 Subject: Adding exifer library --- modules/exif/lib/makers/gps.php | 246 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 modules/exif/lib/makers/gps.php (limited to 'modules/exif/lib/makers/gps.php') diff --git a/modules/exif/lib/makers/gps.php b/modules/exif/lib/makers/gps.php new file mode 100644 index 00000000..28be20f4 --- /dev/null +++ b/modules/exif/lib/makers/gps.php @@ -0,0 +1,246 @@ +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); + } + $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'; + } + } + } 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); + + + } 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)) . + ".". 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 { + $data = bin2hex($data); + if($intel==1) $data = intel2Moto($data); + } + + return $data; +} + + +//================= +// GPS Special data section +// Useful websites +// http://drewnoakes.com/code/exif/sampleOutput.html +// http://www.geosnapper.com +//==================================================================== +function parseGPS($block,&$result,$offset,$seek, $globalOffset) { + + if($result['Endien']=="Intel") $intel=1; + else $intel=0; + + $v = fseek($seek,$globalOffset+$offset); //offsets are from TIFF header which is 12 bytes from the start of the file + if($v==-1) { + $result['Errors'] = $result['Errors']++; + } + + $num = bin2hex(fread( $seek, 2 )); + if($intel==1) $num = intel2Moto($num); + $num=hexdec($num); + $result['GPS']['NumTags'] = $num; + + $block = fread( $seek, $num*12 ); + $place = 0; + + //loop thru all tags Each field is 12 bytes + for($i=0;$i<$num;$i++) { + //2 byte tag + $tag = bin2hex(substr($block,$place,2));$place+=2; + if($intel==1) $tag = intel2Moto($tag); + $tag_name = lookup_GPS_tag($tag); + + //2 byte datatype + $type = bin2hex(substr($block,$place,2));$place+=2; + if($intel==1) $type = intel2Moto($type); + lookup_type($type,$size); + + //4 byte number of elements + $count = bin2hex(substr($block,$place,4));$place+=4; + if($intel==1) $count = intel2Moto($count); + $bytesofdata = $size*hexdec($count); + + //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) { + $result['Errors'] = $result['Errors']++; + } + } + + if($result['VerboseOutput']==1) { + $result['GPS'][$tag_name] = formatGPSData($type,$tag,$intel,$data); + $result['GPS'][$tag_name."_Verbose"]['RawData'] = bin2hex($data); + $result['GPS'][$tag_name."_Verbose"]['Type'] = $type; + $result['GPS'][$tag_name."_Verbose"]['Bytes'] = $bytesofdata; + } else { + $result['GPS'][$tag_name] = formatGPSData($type,$tag,$intel,$data); + } + } +} + + +?> -- cgit v1.2.3