Some improvements to exif handling.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 9 Mar 2010 06:46:50 +0000 (01:46 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 9 Mar 2010 06:48:54 +0000 (01:48 -0500)
Add some missing exif fields and start adding support for composite fields. We store the composite fields already parsed
to both take advantage of exiftool's parsing, as well as to avoid issues with different maker formats.

Now if only Aperture wouldn't nuke most of these fields...

framework/Image/lib/Horde/Image/Exif.php
framework/Image/lib/Horde/Image/Exif/Base.php
framework/Image/lib/Horde/Image/Exif/Exiftool.php

index c02c29e..ff42807 100644 (file)
@@ -119,7 +119,16 @@ class Horde_Image_Exif
                 'Artist' => array('description' => _("Artist"), 'type' => 'text'),
                 'LightSource' => array('description' => _("Light source"), 'type' => 'number'),
                 'ImageStabalization' => array('description' => _("Image Stabilization"), 'type' => 'text'),
+                'SceneCaptureType' => array('description' => _("Scene Type"), 'type' => 'number'),
+
             ),
+
+            'COMPOSITE' => array(
+                'LensID' => array('description' => _("Lens"), 'type' => 'text'),
+                'Aperture' => array('description' => _("Aperture"), 'type' => 'text'),
+                'DOF' => array('description' => _("Depth of Field"), 'type' => 'text'),
+                'FOV' => array('description' => _("Field of View"), 'type' => 'text')
+            )
         );
     }
 
@@ -138,7 +147,7 @@ class Horde_Image_Exif
         if ($driver instanceof Horde_Image_Exif_Base) {
             $supported = $driver->supportedCategories();
         } else {
-            $supported = array('XMP', 'IPTC', 'EXIF');
+            $supported = array('XMP', 'IPTC', 'EXIF'    );
         }
         $categories = self::getCategories();
         $flattened = array();
@@ -466,6 +475,15 @@ class Horde_Image_Exif
             default: return _("Uncalibrated");
             }
 
+        case 'SceneCaptureType':
+            switch ($data) {
+            case 0: return _("Standard");
+            case 1: return _("Landscape");
+            case 2: return _("Portrait");
+            case 3: return _("Night Scene");
+            default: return _("Unknown");
+            }
+
         case 'DateTime':
         case 'DateTimeOriginal':
         case 'DateTimeDigitized':
index 2844db8..6180c45 100644 (file)
@@ -47,8 +47,7 @@ abstract class Horde_Image_Exif_Base
     {
         $results = array();
         if ($exif) {
-            $fields = Horde_Image_Exif::getFields();
-
+            $fields = Horde_Image_Exif::getFields($this);
             foreach ($fields as $field => $data) {
                 $value = isset($exif[$field]) ? $exif[$field] : '';
                 // Don't store empty fields.
index 801ea47..b77a9e4 100644 (file)
@@ -36,27 +36,31 @@ class Horde_Image_Exif_Exiftool extends Horde_Image_Exif_Base
     public function getData($image)
     {
         // Request the full stream of meta data in JSON format.
-        // -j option outputs in JSON, -n = prevent screen formatting
-        // -x DataDump prevents the binary DataDump field from some cameras from
-        // being included. It messes up the JSON decoding, and it's not used
-        // anywhere anyway.
-        $command = '-j -n -x MakerNotes:DataDump ' . $image;
+        // -j option outputs in JSON, appending '#' to the -TAG prevents
+        // screen formatting.
+        $categories = Horde_Image_Exif::getCategories();
+        $tags = '';
+        foreach (array('EXIF', 'IPTC', 'XMP') as $category) {
+            foreach ($categories[$category] as $field => $value) {
+                $tags .= ' -' . $field . '#';
+            }
+        }
+        foreach ($categories['COMPOSITE'] as $field => $value) {
+            $tags .= ' -' . $field;
+        }
+        $command = '-j' . $tags . ' ' . $image;
         $results = json_decode($this->_execute($command));
         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 $this->_processData((array)$results);
+            $exif_results = $this->_processData((array)array_pop($results));
+            return $exif_results;
         }
 
         throw new Horde_Image_Exception('Unknown error running exiftool command');
-
     }
 
     public function supportedCategories()
     {
-        return array('EXIF', 'IPTC', 'XMP');
+        return array('EXIF', 'IPTC', 'XMP', 'COMPOSITE');
     }
 
     /**