From b4e6c89f70097281c07c6f9189fb6c33cc001843 Mon Sep 17 00:00:00 2001 From: tetronomis Date: Mon, 17 Nov 2014 15:02:44 +0100 Subject: [PATCH 1/6] Update imageMetadataParser.php Return raw orientation value --- imageMetadataParser.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/imageMetadataParser.php b/imageMetadataParser.php index 8b5ef36..8936111 100644 --- a/imageMetadataParser.php +++ b/imageMetadataParser.php @@ -190,19 +190,7 @@ 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']); } } From 020e3b62010836a6d2d092a0926140d0311c8481 Mon Sep 17 00:00:00 2001 From: tetronomis Date: Mon, 17 Nov 2014 15:07:28 +0100 Subject: [PATCH 2/6] Update imageMetadataParser.php Added @ in front of exif_read_data to prevent old PHP bug --- imageMetadataParser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imageMetadataParser.php b/imageMetadataParser.php index 8936111..64ede25 100644 --- a/imageMetadataParser.php +++ b/imageMetadataParser.php @@ -25,7 +25,7 @@ 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; @@ -66,7 +66,7 @@ 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; From eb47054e96e6f1c5dac462329baac1faf79efd9f Mon Sep 17 00:00:00 2001 From: tetronomis Date: Mon, 17 Nov 2014 16:24:24 +0100 Subject: [PATCH 3/6] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"], From 0403822517b23942b848628e5f0442a5d010ec55 Mon Sep 17 00:00:00 2001 From: tetronomis Date: Mon, 17 Nov 2014 16:28:40 +0100 Subject: [PATCH 4/6] Update imageMetadataParser.php --- imageMetadataParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imageMetadataParser.php b/imageMetadataParser.php index 64ede25..6a4ff0a 100644 --- a/imageMetadataParser.php +++ b/imageMetadataParser.php @@ -190,7 +190,7 @@ public function hasOrientation() { return isset($this->aAttributes['orientation']); } public function getOrientation() { - return $this->aAttributes['orientation']); + return $this->aAttributes['orientation']; } } From 1626b0368334475661ae2f3250033c08f6dd4c90 Mon Sep 17 00:00:00 2001 From: tetronomis Date: Tue, 9 Dec 2014 12:00:10 +0100 Subject: [PATCH 5/6] Store raw data --- imageMetadataParser.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/imageMetadataParser.php b/imageMetadataParser.php index 6a4ff0a..36724b7 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; @@ -28,7 +30,10 @@ public function parseExif() { $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']); @@ -71,6 +76,9 @@ public function parseIPTC() { if(!isset($info['APP13'])) return false; + // Store raw data + $this->aRaw = $aArr; + $iptc = iptcparse($info['APP13']); if (isset($iptc["2#120"][0])) # caption @@ -192,5 +200,7 @@ public function hasOrientation() { public function getOrientation() { return $this->aAttributes['orientation']; } - + public function getRaw() { + return $this->aRaw; + } } From e84058da948bffdde0df7ebbcd37777ce09c6ab1 Mon Sep 17 00:00:00 2001 From: tetronomis Date: Sun, 4 Jan 2015 23:33:09 +0100 Subject: [PATCH 6/6] Update imageMetadataParser.php --- imageMetadataParser.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/imageMetadataParser.php b/imageMetadataParser.php index 36724b7..6a7bba7 100644 --- a/imageMetadataParser.php +++ b/imageMetadataParser.php @@ -168,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]); @@ -187,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; @@ -203,4 +207,23 @@ public function getOrientation() { 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]); +} }