diff --git a/composer.json b/composer.json index 62c5569..25cbbfe 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "cnlpete/image-metadata-parser", + "name": "tetronomis/image-metadata-parser", "type": "library", "description": "An abstraction to Exif, ITPC and XMP", "keywords": ["php", "exif", "itpc"], diff --git a/imageMetadataParser.php b/imageMetadataParser.php index 8b5ef36..6a7bba7 100644 --- a/imageMetadataParser.php +++ b/imageMetadataParser.php @@ -14,6 +14,8 @@ class ImageMetadataParser { protected $sFilename; protected $aAttributes = array(); + + protected $aRaw; public function __construct($sFilename) { $this->sFilename = $sFilename; @@ -25,10 +27,13 @@ public static function exifAvailable() { } public function parseExif() { - $aArr = exif_read_data($this->sFilename, 'IFD0,THUMBNAIL', true); + $aArr = @exif_read_data($this->sFilename, 'IFD0,THUMBNAIL', true); if ($aArr === false) return false; - + + // Store raw data + $this->aRaw = $aArr; + // the date and time the image was taken if (isset($aArr['IFD0']['DateTime'])) { $iTimestamp = self::timestampFromEXIF($aArr['IFD0']['DateTime']); @@ -66,11 +71,14 @@ public function parseExif() { } public function parseIPTC() { - $aArr = exif_read_data($this->sFilename, 'IDF0', true); + $aArr = @exif_read_data($this->sFilename, 'IDF0', true); $size = getimagesize($this->sFilename, $info); if(!isset($info['APP13'])) return false; + // Store raw data + $this->aRaw = $aArr; + $iptc = iptcparse($info['APP13']); if (isset($iptc["2#120"][0])) # caption @@ -160,6 +168,9 @@ public function hasGPS() { isset($this->aAttributes['gps']['GPSLatitude'][0]); } public function getGPS(&$dLat, &$dLong) { + $dLong = $this->extractGPS($this->aAttributes['gps']['GPSLongitude'], $this->aAttributes['gps']['GPSLongitudeRef']); + $dLat = $this->extractGPS($this->aAttributes['gps']['GPSLatitude'], $this->aAttributes['gps']['GPSLatitudeRef']); + /* $latFirst = explode("/", $this->aAttributes['gps']['GPSLatitude'][0]); $latSecond = explode("/", $this->aAttributes['gps']['GPSLatitude'][1]); $latThird = explode("/", $this->aAttributes['gps']['GPSLatitude'][2]); @@ -179,6 +190,7 @@ public function getGPS(&$dLat, &$dLong) { $longThird = intval($longThird[0]) / intval($longThird[1]); $dLong = $longFirst + ($longSecond*60 + $longThird) / 3600; + */ } public function getGPSArray() { $dLat = 0.0; $dLong = 0.0; @@ -190,19 +202,28 @@ public function hasOrientation() { return isset($this->aAttributes['orientation']); } public function getOrientation() { - switch($this->aAttributes['orientation']) { - case 3: - return 180; - break; - case 6: - return -90; - break; - case 8: - return 90; - break; - default: - return 0; - } + return $this->aAttributes['orientation']; + } + public function getRaw() { + return $this->aRaw; } + + private function extractGPS($exifCoord, $hemi) { + $degrees = count($exifCoord) > 0 ? $this->gps2Num($exifCoord[0]) : 0; + $minutes = count($exifCoord) > 1 ? $this->gps2Num($exifCoord[1]) : 0; + $seconds = count($exifCoord) > 2 ? $this->gps2Num($exifCoord[2]) : 0; + $flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1; + return $flip * ($degrees + $minutes / 60 + $seconds / 3600); + } + + private function gps2Num($coordPart) { + $parts = explode('/', $coordPart); + if (count($parts) <= 0) + return 0; + if (count($parts) == 1) + return $parts[0]; + + return floatval($parts[0]) / floatval($parts[1]); +} }