Process exif data before returning, fixes for differences in data formats returned...
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 3 Aug 2009 21:43:45 +0000 (17:43 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 3 Aug 2009 21:44:46 +0000 (17:44 -0400)
framework/Image/lib/Horde/Image/Exif.php
framework/Image/lib/Horde/Image/Exif/Base.php
framework/Image/lib/Horde/Image/Exif/Exiftool.php

index ab06df8..acb85f7 100644 (file)
@@ -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 : '---';
         }
index 54afa14..5302385 100644 (file)
@@ -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;
         }
index 665b39a..450cbd0 100644 (file)
@@ -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');
+
     }
 
     /**