From 3d36d1f649d343aac2c5a91a45de33e38456ae78 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Tue, 9 Mar 2010 01:46:50 -0500 Subject: [PATCH] Some improvements to exif handling. 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 | 20 +++++++++++++++- framework/Image/lib/Horde/Image/Exif/Base.php | 3 +-- framework/Image/lib/Horde/Image/Exif/Exiftool.php | 28 +++++++++++++---------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/framework/Image/lib/Horde/Image/Exif.php b/framework/Image/lib/Horde/Image/Exif.php index c02c29ec8..ff428070d 100644 --- a/framework/Image/lib/Horde/Image/Exif.php +++ b/framework/Image/lib/Horde/Image/Exif.php @@ -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': diff --git a/framework/Image/lib/Horde/Image/Exif/Base.php b/framework/Image/lib/Horde/Image/Exif/Base.php index 2844db8ce..6180c4522 100644 --- a/framework/Image/lib/Horde/Image/Exif/Base.php +++ b/framework/Image/lib/Horde/Image/Exif/Base.php @@ -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. diff --git a/framework/Image/lib/Horde/Image/Exif/Exiftool.php b/framework/Image/lib/Horde/Image/Exif/Exiftool.php index 801ea47d3..b77a9e48c 100644 --- a/framework/Image/lib/Horde/Image/Exif/Exiftool.php +++ b/framework/Image/lib/Horde/Image/Exif/Exiftool.php @@ -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'); } /** -- 2.11.0