Ansel_Faces_Base::viewExists PHP Method

viewExists() public method

If $create is true, the image is created if it does not exist. Otherwise false is returned if the image does not exist. True is returned both if the image already existed OR if it did not exist, but was successfully created.
public viewExists ( integer $image_id, integer $face_id, boolean $create = true ) : boolean
$image_id integer The image_id the face belongs to.
$face_id integer The face_id we are checking for.
$create boolean Automatically create the image if it is not found.
return boolean True if image exists at end of function call, false otherwise.
    public function viewExists($image_id, $face_id, $create = true)
    {
        $vfspath = Ansel_Faces::getVFSPath($image_id) . 'faces';
        $vfsname = $face_id . Ansel_Faces::getExtension();
        if (!$GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->exists($vfspath, $vfsname)) {
            if (!$create) {
                return false;
            }
            $data = $this->getFaceById($face_id, true);
            $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
            try {
                // Actually create the image.
                $this->createView($face_id, $image, $data['face_x1'], $data['face_y1'], $data['face_x2'], $data['face_y2']);
                $this->saveSignature($image_id, $face_id);
            } catch (Ansel_Exception $e) {
                return false;
            }
        }
        return true;
    }