/** * Get face signature from an existing face image. * * @param integer $image_id Image ID face belongs to * @param integer $face_id Face ID to check * * @throws Ansel_Exception */ 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 $sql = 'UPDATE ansel_faces SET face_signature = ? WHERE face_id = ?'; $params = array(new Horde_Db_Value_Binary(puzzle_compress_cvec($signature)), $face_id); try { $GLOBALS['ansel_db']->update($sql, $params); } 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 ansel_faces_index (face_id, index_position, index_part) VALUES (?, ?, ?)'; $c = $str_len - $word_len; for ($i = 0; $i <= $c; $i++) { $data = array($face_id, $i, new Horde_Db_Value_Binary(substr($signature, $i, $word_len))); try { $GLOBALS['ansel_db']->insert($q, $data); } catch (Horde_Db_Exception $e) { throw new Ansel_Exception($e); } } }
* @author Duck <*****@*****.**> */ require_once __DIR__ . '/../lib/Application.php'; Horde_Registry::appInit('ansel'); $face_id = Horde_Util::getFormData('face'); $faces = $GLOBALS['injector']->getInstance('Ansel_Faces'); // Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file // header if ($conf['vfs']['src'] == 'sendfile') { $face = $faces->getFaceById($face_id); // Make sure the view exists if (!$faces->viewExists($face['image_id'], $face_id, true)) { Horde::log(sprintf('Unable to locate or create face_id %u.', $face_id)); exit; } // We definitely have an image for the face. try { $filename = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->readFile(Ansel_Faces::getVFSPath($face['image_id']) . 'faces', $face_id . Ansel_Faces::getExtension()); } catch (Horde_Vfs_Exception $e) { Horde::log($e, 'ERR'); exit; } header('Content-type: image/' . $GLOBALS['conf']['image']['type']); header('X-LIGHTTPD-send-file: ' . $filename); header('X-Sendfile: ' . $filename); exit; } // Run it through PHP $img = $faces->getFaceImageObject($face_id); header('Content-type: image/' . $GLOBALS['conf']['image']['type']); echo $img->raw();