From d06a195fac7758cfc26312decb889fbab6d3dd6f Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Mon, 3 Aug 2009 17:43:45 -0400 Subject: [PATCH] Process exif data before returning, fixes for differences in data formats returned etc... --- framework/Image/lib/Horde/Image/Exif.php | 2 ++ framework/Image/lib/Horde/Image/Exif/Base.php | 13 +++++++++++-- framework/Image/lib/Horde/Image/Exif/Exiftool.php | 13 +++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/framework/Image/lib/Horde/Image/Exif.php b/framework/Image/lib/Horde/Image/Exif.php index ab06df863..acb85f74a 100644 --- a/framework/Image/lib/Horde/Image/Exif.php +++ b/framework/Image/lib/Horde/Image/Exif.php @@ -101,6 +101,7 @@ class Horde_Image_Exif 'GPSLongitude' => array('description' => _("Longitude"), 'type' => 'gps'), 'LightSource' => array('description' => _("Light source"), 'type' => 'number'), 'FileSource' => array('description' => _("File source"), 'type' => 'number'), + 'Keywords' => array('description' => _("Image keywords"), 'type' => 'array') ); } @@ -422,6 +423,7 @@ class Horde_Image_Exif // introduce a dependency on Horde_String to do the conversion). $data = trim(substr($data, 7)) ; + default: return !empty($data) ? $data : '---'; } diff --git a/framework/Image/lib/Horde/Image/Exif/Base.php b/framework/Image/lib/Horde/Image/Exif/Base.php index 54afa14ea..5302385ea 100644 --- a/framework/Image/lib/Horde/Image/Exif/Base.php +++ b/framework/Image/lib/Horde/Image/Exif/Base.php @@ -57,8 +57,12 @@ abstract class Horde_Image_Exif_Base /* Special handling of GPS data */ if ($data['type'] == 'gps') { - $value = self::_parseGPSData($exif[$field]); - if (!empty($exif[$field . 'Ref']) && ($exif[$field . 'Ref'] == 'S' || $exif[$field . 'Ref'] == 'W')) { + $value = $this->_parseGPSData($exif[$field]); + if (!empty($exif[$field . 'Ref']) && ($exif[$field . 'Ref'] == 'S' || + $exif[$field . 'Ref'] == 'South' || + $exif[$field . 'Ref'] == 'W' || + $exif[$field . 'Ref'] == 'West')) { + $value = '-' . $value; } } @@ -93,6 +97,11 @@ abstract class Horde_Image_Exif_Base { // According to EXIF standard, GPS data can be in the form of // dd/1 mm/1 ss/1 or as a decimal reprentation. + if (!is_array($data)) { + // Assume a scalar is a decimeal representation - but strip it of + // any stray characters that may be there. + return (double)trim(str_replace(array('N', 'S', 'E', 'W', '"'), array('', '', '', '', ''), $data)); + } if ($data[0] == 0) { return 0; } diff --git a/framework/Image/lib/Horde/Image/Exif/Exiftool.php b/framework/Image/lib/Horde/Image/Exif/Exiftool.php index 665b39a83..450cbd084 100644 --- a/framework/Image/lib/Horde/Image/Exif/Exiftool.php +++ b/framework/Image/lib/Horde/Image/Exif/Exiftool.php @@ -36,15 +36,20 @@ class Horde_Image_Exif_Exiftool extends Horde_Image_Exif_Base public function getData($image) { // Request the full stream of meta data in JSON format. - $command = '-j ' . $image; + $command = '-j -c "%.6f ' . $image; $test = $this->_execute($command); $results = json_decode($this->_execute($command)); - var_dump($results); + if (is_array($results)) { + $results = array_pop($results); + } + + // Return as an array since that's what all the other Exif classes do... if ($results instanceof stdClass) { - return $results; + return $this->_processData((array)$results); } - throw new Horde_Image_Exception('Unknown error running exiftool command.'); + throw new Horde_Image_Exception('Unknown error running exiftool command'); + } /** -- 2.11.0