Example #1
0
 /**
  * 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);
         }
     }
 }
Example #2
0
<?php

/**
 * Process an single image (to be called by ajax)
 *
 * Copyright 2008-2014 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author Duck <*****@*****.**>
 */
require_once __DIR__ . '/../../lib/Application.php';
Horde_Registry::appInit('ansel');
$thumb = Horde_Util::getGet('thumb');
$tmp = Horde::getTempDir();
$path = $tmp . '/search_face_' . ($thumb ? 'thumb_' : '') . $registry->getAuth() . Ansel_Faces::getExtension();
header('Content-type: image/' . $conf['image']['type']);
readfile($path);
Example #3
0
<?php

/**
 * Process an single image (to be called by ajax)
 *
 * Copyright 2008-2015 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author Duck <*****@*****.**>
 */
require_once 'tabs.php';
/* check if image exists */
$tmp = Horde::getTempDir();
$path = $tmp . '/search_face_' . $registry->getAuth() . Ansel_Faces::getExtension();
if (file_exists($path) !== true) {
    $notification->push(_("You must upload the search photo first"));
    Horde::url('faces/search/image.php')->redirect();
}
$title = _("Create a new face");
$x1 = 0;
$y1 = 0;
$x2 = 0;
$y2 = 0;
try {
    $faces = $faces->getFaces($path);
} catch (Ansel_Exception $e) {
    exit;
}
if (count($faces) > 1) {
Example #4
0
 * @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();