PHP code example of xsolve-pl / face-validator-bundle
1. Go to this page and download the library: Download xsolve-pl/face-validator-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xsolve-pl / face-validator-bundle example snippets
// app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new XSolve\FaceValidatorBundle\XSolveFaceValidatorBundle(),
];
}
}
// src/AppBundle/Entity/User.php
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
use XSolve\FaceValidatorBundle\Validator\Constraints as XSolveAssert;
class User
{
/**
* @var UploadedFile
*
* @Assert\Image()
* @XSolveAssert\Face()
*/
public $profilePicture;
}
// src/AppBundle/Controller/UserController.php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\User;
class UserController extends Controller
{
/**
* @Route("/user/new", name="app_user_new")
*/
public function newAction(Request $request)
{
$user = new User();
$form = $this->createFormBuilder($user)
->add('profilePicture', FileType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// ...
}
// ...
}
}
// src/AppBundle/Entity/User.php
use Symfony\Component\Validator\Constraints as Assert;
use XSolve\FaceValidatorBundle\Validator\Constraints as XSolveAssert;
class User
{
/**
* @var Symfony\Component\HttpFoundation\File\UploadedFile
* @Assert\Image()
* @XSolveAssert\Face(
* minFaceRatio = 0.15,
* allowCoveringFace = true,
* maxFaceRotation = 20.0,
* allowGlasses = true,
* allowSunglasses = true,
* allowMakeup = true,
* allowNoHair = true,
* maxBlurLevel = high,
* maxNoiseLevel = high,
* noFaceMessage = 'Face is not visible.',
* faceTooSmallMessage = 'Face is too small.',
* faceCoveredMessage = 'Face cannot be covered.',
* hairCoveredMessage = 'Hair cannot be covered.',
* tooMuchRotatedMessage = 'Face is too much rotated.',
* glassesMessage = 'There should be no glasses in the picture.',
* sunglassesMessage = 'There should be no sunglasses in the picture.',
* makeupMessage = 'The person should not be wearing any makeup.',
* blurredMessage = 'The picture is too blurred.',
* noiseMessage = 'The picture is too noisy.'
* )
*/
public $profilePicture;
}
// src/AppBundle/Controller/ImageController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class ImageController extends Controller
{
public function validateAction(Request $request)
{
/* @var $validator ValidatorInterface */
$validator = $this->get('validator');
$constraintViolations = $validator->validate(
'/path/to/your/image/file.png',
new Face([
// you can pass the options mentioned before to the validation constraint
])
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.