Skip to content

Instantly share code, notes, and snippets.

Last active Mar 11, 2021
What would you like to do?
Apply a blur filter automatically for each detected face using the PixLab Rest API (PHP Sample)
* PixLab PHP Client which is just a single class PHP file without any dependency that you can get from Github
require_once "pixlab.php";
# Detect all human faces in a given image via `facedetect` and blur all of them via `mogrify`.
# & for additional information.
# Target Image we want to blur face(s) on
$img = '';
# Your PixLab API key
$key = 'PIXLAB_API_KEY';
$pix = new Pixlab($key);
echo "Detecting faces first...\n";
/* Invoke facedetect first */
if( !$pix->get('facedetect',array('img' => $img)) ){
echo $pix->get_error_message();
/* Grab the total number of detected faces */
$faces = $pix->json->faces;
echo "Total number of detected faces: ".count($faces)."\n";
if( count($faces) < 1 ){
echo "No human faces were were detected on this picture\n";
echo "Blurring faces...\n";
/* Call mogrify via POST and pass the facial coordinates extracted earlier */
if( !$pix->post('mogrify', ['img' => $img,'cord' => $faces]) ){
echo $pix->get_error_message();
echo "Blurred faces URL: ".$pix->json->link."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment