Skip to content

Commit

Permalink
Get attributes from the attribute object.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jun 17, 2014
1 parent 6a16572 commit 7c13445
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
23 changes: 23 additions & 0 deletions ansel/lib/Attributes.php
Expand Up @@ -102,6 +102,29 @@ public function imageAttributes($attributes = array(), $replacing = false)
return $exif;
}

/**
* Return the stored image attributes.
*
* @return array The array of image attributes.
*/
public function getAttributes()
{
$attributes = $GLOBALS['storage']->getImageAttributes($this->_id);
$fields = Horde_Image_Exif::getFields($this->_exif);
$output = array();
foreach (array_keys($fields) as $field) {
if (!isset($attributes[$field])) {
continue;
}
$output[$field] = Horde_Image_Exif::getHumanReadable(
$field,
Horde_String::convertCharset($attributes[$field], $GLOBALS['conf']['sql']['charset'], 'UTF-8')
);
}

return $output;
}

/**
* Return a suitable image title from exif data. Taken from the first
* non-empty Horde_Image_Exif::getTitleFields() field.
Expand Down
32 changes: 2 additions & 30 deletions ansel/lib/Image.php
Expand Up @@ -654,12 +654,7 @@ public function replace(array $imageData)
// Reset the data array and remove all cached images
$this->_data = array();
$this->reset();

// Remove attributes
$GLOBALS['storage']->clearImageAttributes($this->id);

// Load the new image data
$this->getEXIF();
$this->getEXIF(true);
$this->updateData($imageData);
}

Expand Down Expand Up @@ -1311,30 +1306,7 @@ public function getViewHash($view, Ansel_Style $style = null)
*/
public function getAttributes()
{
$attributes = $GLOBALS['storage']->getImageAttributes($this->id);
$params = !empty($GLOBALS['conf']['exif']['params']) ?
$GLOBALS['conf']['exif']['params'] :
array();
$params['logger'] = $GLOBALS['injector']->getInstance('Horde_Log_Logger');

$exif = Horde_Image_Exif::factory(
$GLOBALS['conf']['exif']['driver'],
$params
);
$fields = Horde_Image_Exif::getFields($exif);

$output = array();
foreach ($fields as $field => $data) {
if (!isset($attributes[$field])) {
continue;
}
$output[$field] = $value = Horde_Image_Exif::getHumanReadable(
$field,
Horde_String::convertCharset($attributes[$field], $GLOBALS['conf']['sql']['charset'], 'UTF-8')
);
}

return $output;
return $this->_getAttributeObject()->getAttributes();
}

/**
Expand Down

0 comments on commit 7c13445

Please sign in to comment.