function saveSignature($image_id, $face_id)
{
// can we get it?
if (empty($GLOBALS['conf']['faces']['search']) || Horde_Util::loadExtension('libpuzzle') === false) {
return;
}
// Ensure we have an on-disk file to read the signature from.
$path = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->readFile(Ansel_Faces::getVFSPath($image_id) . '/faces', $face_id . Ansel_Faces::getExtension());
$signature = puzzle_fill_cvec_from_file($path);
if (empty($signature)) {
return;
}
// save compressed signature
try {
$GLOBALS['ansel_db']->updateBlob('ansel_faces', array('face_signature' => new Horde_Db_Value_Binary(puzzle_compress_cvec($signature))), array('face_id = ?', $face_id));
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($result);
}
// create index
$word_len = $GLOBALS['conf']['faces']['search'];
$str_len = strlen($signature);
$GLOBALS['ansel_db']->delete('DELETE FROM ansel_faces_index WHERE face_id = ' . $face_id);
$q = 'INSERT INTO () VALUES (?, ?, ?)';
$c = $str_len - $word_len;
for ($i = 0; $i <= $c; $i++) {
$data = array('face_id' => $face_id, 'index_position' => $i, 'index_part' => new Horde_Db_Value_Binary(substr($signature, $i, $word_len)));
try {
$GLOBALS['ansel_db']->insertBlob('ansel_faces_index', $data);
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($e);
}
}
}