More flexibility in obtaining supported metadata fields.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 5 Aug 2009 18:36:44 +0000 (14:36 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 5 Aug 2009 18:38:01 +0000 (14:38 -0400)
framework/Image/lib/Horde/Image/Exif.php
framework/Image/lib/Horde/Image/Exif/Base.php
framework/Image/lib/Horde/Image/Exif/Bundled.php
framework/Image/lib/Horde/Image/Exif/Exiftool.php
framework/Image/lib/Horde/Image/Exif/Php.php

index acb85f7..4c0a95b 100644 (file)
@@ -62,50 +62,98 @@ class Horde_Image_Exif
      *
      * @return array
      */
-    static public function getFields()
+    static public function getCategories()
     {
-        return array('Make' => array('description' => _("Camera Make"), 'type' => 'text'),
-                     'Model' => array('description' => _("Camera Model"), 'type' => 'text'),
-                     'Software' => array('description' => _("Software Version"), 'type' => 'text'),
-                     'ImageType' => array('description' => _("Photo Type"), 'type' => 'text'),
-                     'ImageDescription' => array('description' => _("Photo Description"), 'type' => 'text'),
-                     'FileSize' => array('description' => _("File Size"), 'type' => 'number'),
-                     'DateTime' => array('description' => _("Date Photo Modified"), 'type' => 'date'),
-                     'DateTimeOriginal' => array('description' => _("Date Photo Taken"), 'type' => 'date'),
-                     'DateTimeDigitized' => array('description' => _("Date Photo Digitized"), 'type' => 'date'),
-                     'ExifImageWidth' => array('description' => _("Width"), 'type' => 'number'),
-                     'ExifImageLength' => array('description' => _("Height"), 'type' => 'number'),
-                     'XResolution' => array('description' => _("X Resolution"), 'type' => 'number'),
-                     'YResolution' => array('description' => _("Y Resolution"), 'type' => 'number'),
-                     'ResolutionUnit' => array('description' => _("Resolution Unit"), 'type' => 'text'),
-                     'ShutterSpeedValue' => array('description' => _("Shutter Speed"), 'type' => 'number'),
-                     'ExposureTime' => array('description' => _("Exposure"), 'type' => 'number'),
-                     'FocalLength' => array('description' => _("Focal Length"), 'type' => 'number'),
-                     'FocalLengthIn35mmFilm' => array('description' => _("Focal Length (35mm equiv)"), 'type' => 'number'),
-                     'ApertureValue' => array('description' => _("Aperture"), 'type' => 'number'),
-                     'FNumber' => array('description' => _("F-Number"), 'type' => 'number'),
-                     'ISOSpeedRatings' => array('description' => _("ISO Setting"), 'type' => 'number'),
-                     'ExposureBiasValue' => array('description' => _("Exposure Bias"), 'type' => 'number'),
-                     'ExposureMode' => array('description' => _("Exposure Mode"), 'type' => 'number'),
-                     'ExposureProgram' => array('description' => _("Exposure Program"), 'type' => 'number'),
-                     'MeteringMode' => array('description' => _("Metering Mode"), 'type' => 'number'),
-                     'Flash' => array('description' => _("Flash Setting"), 'type' => 'number'),
-                     'UserComment' => array('description' => _("User Comment"), 'type' => 'text'),
-                     'ColorSpace' => array('description' => _("Color Space"), 'type' => 'number'),
-                     'SensingMethod' => array('description' => _("Sensing Method"), 'type' => 'number'),
-                     'WhiteBalance' => array('description' => _("White Balance"), 'type' => 'number'),
-                     'Orientation' => array('description' => _("Camera Orientation"), 'type' => 'number'),
-                     'Copyright' => array('description' => _("Copyright"), 'type' => 'text'),
-                     'Artist' => array('description' => _("Artist"), 'type' => 'text'),
-                     'GPSLatitude' => array('description' => _("Latitude"), 'type' => 'gps'),
-                     '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')
+        return array(
+            'IPTC' => array(
+                'Keywords' => array('description' => _("Image keywords"), 'type' => 'array'),
+                'ObjectName' => array('description' => _("Image Title"), 'type' => 'text'),
+                'By-line' => array('description' => _("By"), 'type' => 'text'),
+                'CopyrightNotice' => array('description' => _("Copyright"), 'type' => 'text'),
+            ),
+
+            'XMP' => array(
+                'Creator' => array('description' => _("Image Creator"), 'type' => 'text'),
+                'Rights' => array('description' => _("Rights"), 'type' => 'text'),
+                'UsageTerms' => array('description' => _("Usage Terms"), 'type' => 'type'),
+            ),
+
+            'EXIF' => array(
+                'DateTime' => array('description' => _("Date Photo Modified"), 'type' => 'date'),
+                'DateTimeOriginal' => array('description' => _("Date Photo Taken"), 'type' => 'date'),
+                'DateTimeDigitized' => array('description' => _("Date Photo Digitized"), 'type' => 'date'),
+                'GPSLatitude' => array('description' => _("Latitude"), 'type' => 'gps'),
+                'GPSLongitude' => array('description' => _("Longitude"), 'type' => 'gps'),
+                'Make' => array('description' => _("Camera Make"), 'type' => 'text'),
+                'Model' => array('description' => _("Camera Model"), 'type' => 'text'),
+                'Software' => array('description' => _("Software Version"), 'type' => 'text'),
+                'ImageType' => array('description' => _("Photo Type"), 'type' => 'text'),
+                'ImageDescription' => array('description' => _("Photo Description"), 'type' => 'text'),
+                'FileSize' => array('description' => _("File Size"), 'type' => 'number'),
+                'ExifImageWidth' => array('description' => _("Width"), 'type' => 'number'),
+                'ExifImageLength' => array('description' => _("Height"), 'type' => 'number'),
+                'XResolution' => array('description' => _("X Resolution"), 'type' => 'number'),
+                'YResolution' => array('description' => _("Y Resolution"), 'type' => 'number'),
+                'ResolutionUnit' => array('description' => _("Resolution Unit"), 'type' => 'text'),
+                'ShutterSpeedValue' => array('description' => _("Shutter Speed"), 'type' => 'number'),
+                'ExposureTime' => array('description' => _("Exposure"), 'type' => 'number'),
+                'FocalLength' => array('description' => _("Focal Length"), 'type' => 'number'),
+                'FocalLengthIn35mmFilm' => array('description' => _("Focal Length (35mm equiv)"), 'type' => 'number'),
+                'ApertureValue' => array('description' => _("Aperture"), 'type' => 'number'),
+                'FNumber' => array('description' => _("F-Number"), 'type' => 'number'),
+                'ISOSpeedRatings' => array('description' => _("ISO Setting"), 'type' => 'number'),
+                'ExposureBiasValue' => array('description' => _("Exposure Bias"), 'type' => 'number'),
+                'ExposureMode' => array('description' => _("Exposure Mode"), 'type' => 'number'),
+                'ExposureProgram' => array('description' => _("Exposure Program"), 'type' => 'number'),
+                'MeteringMode' => array('description' => _("Metering Mode"), 'type' => 'number'),
+                'Flash' => array('description' => _("Flash Setting"), 'type' => 'number'),
+                'UserComment' => array('description' => _("User Comment"), 'type' => 'text'),
+                'ColorSpace' => array('description' => _("Color Space"), 'type' => 'number'),
+                'SensingMethod' => array('description' => _("Sensing Method"), 'type' => 'number'),
+                'WhiteBalance' => array('description' => _("White Balance"), 'type' => 'number'),
+                'Orientation' => array('description' => _("Camera Orientation"), 'type' => 'number'),
+                'Copyright' => array('description' => _("Copyright"), 'type' => 'text'),
+                'Artist' => array('description' => _("Artist"), 'type' => 'text'),
+                'LightSource' => array('description' => _("Light source"), 'type' => 'number'),
+                'FileSource' => array('description' => _("File source"), 'type' => 'number'),
+                'ImageStabalization' => array('description' => _("Image Stabilization"), 'type' => 'text'),
+            ),
         );
     }
 
     /**
+     * Return a flattened array of supported metadata fields.
+     *
+     * @param $driver
+     * @return unknown_type
+     */
+    static public function getFields($driver = null, $description_only = false)
+    {
+        if (!is_null($driver) && is_array($driver)) {
+            $driver = self::factory($driver[0], $driver[1]);
+        }
+        if ($driver instanceof Horde_Image_Exif_Base) {
+            $supported = $driver->supportedCategories();
+        } else {
+            $supported = array('XMP', 'IPTC', 'EXIF');
+        }
+        $categories = self::getCategories();
+        $flattened = array();
+        foreach ($supported as $category) {
+            $flattened = array_merge($flattened, $categories[$category]);
+        }
+
+        if ($description_only) {
+            foreach ($flattened as $key => $data) {
+                $return[$key] = $data['description'];
+            }
+            return $return;
+        }
+
+        return $flattened;
+    }
+
+    /**
      * More human friendly exposure formatting.
      */
     static protected function _formatExposure($data) {
@@ -386,7 +434,9 @@ class Horde_Image_Exif
            return round($data/pow(1024, $e), 2) . ' ' . $s[$e];
 
         case 'FileSource':
+            var_dump($data);
             $data = bin2hex($data);
+            var_dump($data);
             $data = str_replace('00', '', $data);
             $data = str_replace('03', _("Digital Still Camera"), $data);
             return $data;
index bea1cc2..7fd732c 100644 (file)
@@ -155,6 +155,7 @@ abstract class Horde_Image_Exif_Base
     }
 
     abstract public function getData($image);
+    abstract public function supportedCategories();
 
 
 }
\ No newline at end of file
index 9ab0b99..6897e0e 100644 (file)
@@ -702,4 +702,9 @@ class Horde_Image_Exif_Bundled extends Horde_Image_Exif_Base
         return $type;
     }
 
+    public function supportedCategories()
+    {
+        return array('EXIF');
+    }
+
 }
\ No newline at end of file
index 1c643cf..234ebb5 100644 (file)
@@ -38,7 +38,6 @@ class Horde_Image_Exif_Exiftool extends Horde_Image_Exif_Base
         // Request the full stream of meta data in JSON format.
         // -j option outputs in JSON, -n = prevent screen formatting
         $command = '-j -n ' . $image;
-        $test = $this->_execute($command);
         $results = json_decode($this->_execute($command));
         if (is_array($results)) {
             $results = array_pop($results);
@@ -53,6 +52,11 @@ class Horde_Image_Exif_Exiftool extends Horde_Image_Exif_Base
 
     }
 
+    public function supportedCategories()
+    {
+        return array('EXIF', 'IPTC', 'XMP');
+    }
+
     /**
      * Executes a exiftool command.
      *
index bf380d7..e2e310f 100644 (file)
@@ -19,4 +19,9 @@ class Horde_Image_Exif_Php extends Horde_Image_Exif_Base
         return $this->_processData($exif);
     }
 
+    public function supportedCategories()
+    {
+        return array('EXIF');
+    }
+
 }