exif

The XML Google Maps exif class.

Defined (1)

The class is defined in the following location(s).

/xmlgooglemaps_exif.php  
  1. class exif { 
  2.  
  3. var $imagePath = ""; 
  4. var $exifData = array(); 
  5. var $isValid = false; 
  6.  
  7. function exif($filePath) { 
  8. $this->imagePath = $filePath; 
  9. if ( !file_exists( $this->imagePath ) ) 
  10. $this->isValid = false; 
  11. } else { 
  12. $this->isValid = true; 
  13. $size = getimagesize ( $this->imagePath, $metaData );  
  14. }  
  15.  
  16. if ($this->isValid && $size && is_array($metaData)) {  
  17. // get exif - data 
  18. if ( is_callable('exif_read_data')) 
  19. $this->exifData = @exif_read_data($this->imagePath, 0, true ); 
  20. $this->isValid = true; 
  21. } else { 
  22. $this->isValid = false; 
  23. }  
  24. } else { 
  25. $this->isValid = false; 
  26.  
  27. function getGPSLongitude() { 
  28. if ($this->isValid) { 
  29. if (!empty($this->exifData["GPS"]["GPSLongitude"])) { 
  30. $ret = $this->frac2dec($this->exifData["GPS"]["GPSLongitude"][0]); 
  31. $ret += $this->frac2dec($this->exifData["GPS"]["GPSLongitude"][1])/60; 
  32. $ret += $this->frac2dec($this->exifData["GPS"]["GPSLongitude"][2])/3600; 
  33. if (strtolower($this->exifData["GPS"]["GPSLongitudeRef"])=="w") { 
  34. $ret = -1 * $ret; 
  35. return $ret; 
  36. } else { 
  37. return 0; 
  38. } else { 
  39. return 0; 
  40. }  
  41.  
  42. function getGPSLatitude() { 
  43. if ($this->isValid) { 
  44. if (!empty($this->exifData["GPS"]["GPSLatitude"])) { 
  45. $ret = $this->frac2dec($this->exifData["GPS"]["GPSLatitude"][0]); 
  46. $ret += $this->frac2dec($this->exifData["GPS"]["GPSLatitude"][1])/60; 
  47. $ret += $this->frac2dec($this->exifData["GPS"]["GPSLatitude"][2])/3600; 
  48. if (strtolower($this->exifData["GPS"]["GPSLatitudeRef"])=="s") { 
  49. $ret = -1 * $ret; 
  50. return $ret; 
  51. } else { 
  52. return 0; 
  53. } else { 
  54. return 0; 
  55. }  
  56.  
  57. function getCreationDateTime() { 
  58. if (!empty($this->exifData["EXIF"]["DateTimeDigitized"])) { 
  59. return $this->date2ts($this->exifData["EXIF"]["DateTimeDigitized"]); 
  60. } else { 
  61. return 0; 
  62.  
  63. function echoOutput() { 
  64. if ($this->isValid) { 
  65. foreach ($this->exifData as $key => $section) { 
  66. foreach ($section as $name => $val) { 
  67. echo "$key.$name: $val<br />\n"; 
  68. }  
  69. } else { 
  70. echo "error"; 
  71. }  
  72.  
  73. // convert a fraction string to a decimal 
  74. function frac2dec($str) { 
  75. @list( $n, $d ) = explode( '/', $str ); 
  76. if ( !empty($d) ) 
  77. return $n / $d; 
  78. return $str; 
  79.  
  80. // convert the exif date format to a unix timestamp 
  81. function date2ts($str) { 
  82. // seriously, who formats a date like 'YYYY:MM:DD hh:mm:ss'? 
  83. @list( $date, $time ) = explode( ' ', trim($str) ); 
  84. @list( $y, $m, $d ) = explode( ':', $date ); 
  85.  
  86. return strtotime( "{$y}-{$m}-{$d} {$time}" );