Ansel_Faces_Base::saveCustomFace PHP Method

saveCustomFace() public method

Associates a given rectangle with the given image and creates the face image. Used for setting a face range explicitly.
public saveCustomFace ( integer $face_id, integer $image_id, integer $x1, integer $y1, integer $x2, integer $y2, string $name = '' ) : array
$face_id integer Face id to save
$image_id integer Image face belongs to
$x1 integer The top left corner of the cropped image.
$y1 integer The top right corner of the cropped image.
$x2 integer The bottom left corner of the cropped image.
$y2 integer The bottom right corner of the cropped image.
$name string Face name
return array Faces found
    public function saveCustomFace($face_id, $image_id, $x1, $y1, $x2, $y2, $name = '')
    {
        $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
        $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."));
        }
        // Store face id db
        if (!empty($face_id)) {
            $sql = 'UPDATE ansel_faces SET face_name = ?, face_x1 = ?, ' . 'face_y1 = ?, face_x2 = ?, face_y2 = ? WHERE face_id = ?';
            $params = array($name, $x1, $y1, $x2, $y2, $face_id);
            try {
                $GLOBALS['ansel_db']->update($sql, $params);
            } catch (Horde_Db_Exception $e) {
                throw new Ansel_Exception($e);
            }
        } else {
            $sql = 'INSERT INTO ansel_faces (image_id, gallery_id, face_name, ' . ' face_x1, face_y1, face_x2, face_y2)' . ' VALUES (?, ?, ?, ?, ?, ?, ?)';
            $params = array($image->id, $image->gallery, $name, $x1, $y1, $x2, $y2);
            try {
                $face_id = $GLOBALS['ansel_db']->insert($sql, $params);
            } catch (Horde_Db_Exception $e) {
                throw new Ansel_Exception($e);
            }
        }
        // Process the image
        $this->createView($face_id, $image, $x1, $y1, $x2, $y2);
        // Update gallery and image counts
        try {
            $GLOBALS['ansel_db']->update('UPDATE ansel_images SET image_faces = image_faces + 1 WHERE image_id = ' . $image->id);
            $GLOBALS['ansel_db']->update('UPDATE ansel_shares SET attribute_faces = attribute_faces + 1 WHERE share_id = ' . $image->gallery);
        } catch (Horde_Db_Exception $e) {
            throw new Ansel_Exception($e);
        }
        // Save signature
        $this->saveSignature($image->id, $face_id);
        return $face_id;
    }