Skip to content

Commit

Permalink
Implement Horde_Image_Exif::getTitleFields and ::getDescriptionFields.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jun 16, 2014
1 parent 0b620a1 commit 0db4a8d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
77 changes: 75 additions & 2 deletions framework/Image/lib/Horde/Image/Exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
*/
class Horde_Image_Exif
{
static protected $_titleFields = array(
'IPTC' => array('ObjectName'),
'XMP' => array('Title'),
'EXIF' => array()
);

static protected $_descriptionFields = array(
'IPTC' => array('Caption-Abstract'),
'XMP' => array('Description'),
'EXIF' => array('ImageDescription')
);

/**
* Factory method for instantiating a Horde_Image_Exif object.
*
Expand Down Expand Up @@ -134,11 +146,72 @@ static public function getCategories()
);
}

/**
* Return a list of metadata fields that can by used for image titles.
*
* @param mixed $driver A Horde_Image_Exif_Base instance or a string
* specifying the driver in use.
*
* @return array An array of metadata field names.
* @since 2.1.0
*/
static public function getTitleFields($driver = null)
{
$map = self::getCategories();
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');
}

$fields = array();
foreach ($supported as $category) {
$fields = array_merge($fields, self::$_titleFields[$category]);
}

return $fields;
}

/**
* Return a list of metadata fields that can by used for image descriptions.
*
* @param mixed $driver A Horde_Image_Exif_Base instance or a string
* specifying the driver in use.
*
* @return array An array of metadata field names.
* @since 2.1.0
*/
static public function getDescriptionFields($driver = null)
{
$map = self::getCategories();
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');
}

$fields = array();
foreach ($supported as $category) {
$fields = array_merge($fields, self::$_descriptionFields[$category]);
}

return $fields;
}

/**
* Return a flattened array of supported metadata fields.
*
* @param $driver
* @return unknown_type
* @param mixed $driver A Horde_Image_Exif_Base instance or a string
* specifying the driver in use.
* @param boolean $description_only Only return the field descriptions.
*
* @return array
*/
static public function getFields($driver = null, $description_only = false)
{
Expand Down
14 changes: 14 additions & 0 deletions framework/Image/test/Horde/Image/Exif/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ public function setUp()
}
}

public function testTitleFields()
{
$fields = Horde_Image_Exif::getTitleFields();
$this->assertTrue(array_search('ObjectName', $fields) !== false);
$this->assertTrue(array_search('Title', $fields) !== false);
}
public function testDescriptionFields()
{
$descFields = Horde_Image_Exif::getDescriptionFields();
$this->assertTrue(array_search('ImageDescription', $descFields) !== false);
$this->assertTrue(array_search('Description', $descFields) !== false);
$this->assertTrue(array_search('Caption-Abstract', $descFields) !== false);
}

/**
* Tests ability to extract EXIF data without errors. Does not test data
* for validity.
Expand Down

0 comments on commit 0db4a8d

Please sign in to comment.