public function getFromPicture($image, $create = false)
{
// get image if ID is passed
if (!$image instanceof Ansel_Image) {
$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image);
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
throw new Horde_Exception_PermissionDenied(_("Access denied editing the photo."));
}
}
// Get the rectangles for any faces in this image.
$faces = $this->getFaces($image);
if (empty($faces)) {
return array();
}
// Clean up any existing faces we may have had in this image.
Ansel_Faces::delete($image);
// Process faces
$fids = array();
foreach ($faces as $i => $rect) {
// Store face id db
$sql = 'INSERT INTO ansel_faces (image_id, gallery_id, face_x1, ' . ' face_y1, face_x2, face_y2)' . ' VALUES (?, ?, ?, ?, ?, ?)';
$params = $this->_getParamsArray($image, $rect);
try {
$face_id = $GLOBALS['ansel_db']->insert($sql, $params);
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($result);
}
if ($create) {
$this->_createView($face_id, $image, $rect);
// Clear any loaded views to save on memory usage.
$image->reset();
$this->saveSignature($image->id, $face_id);
}
$fids[$face_id] = '';
}
// Update gallery and image counts
try {
$GLOBALS['ansel_db']->update('UPDATE ansel_images SET image_faces = ' . count($fids) . ' WHERE image_id = ' . $image->id);
$GLOBALS['ansel_db']->update('UPDATE ansel_shares ' . 'SET attribute_faces = attribute_faces + ' . count($fids) . ' WHERE share_id = ' . $image->gallery);
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($e);
}
// Expire gallery cache
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
}
return $fids;
}