PHP Classes

pixlab PHP Facedetect and Image Processing: Process images using the PixLab Machine Vision API

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-09-08 (13 days ago) RSS 2.0 feedNot enough user ratingsTotal: 140 This week: 7All time: 8,478 This week: 82Up
Version License PHP version Categories
pixlab-php 1.0Custom (specified...5PHP 5, Graphics, Web services
Description Author

This class can process images using the PixLab Machine Vision API.

It can send HTTP GET and POST requests to the PixLab API server to perform several types of operations on images.

Currently it supports all API request types to perform operations like detecting faces on images, blurring faces, applying Snapchat like filters, etc..


I need a PHP class for face matching
Solution to match faces from uploaded pictures

recognising a face on an image
script should be able to recognize passport pictures

Innovation Award
PHP Programming Innovation award nominee
August 2017
Detecting faces in images can be useful for instance to blur faces that you may not want to be recognized.

This package can detect and blur faces in images using the PixLab Machine Vision API.

Manuel Lemos
Name: Symisc Systems <contact>
Classes: 1 package by
Country: South Africa South Africa
Age: ???
All time rank: 399923 in South Africa South Africa
Week rank: 98 Up1 in South Africa South Africa Up
Innovation award
Innovation award
Nominee: 1x



This is the official PixLab PHP Client for the PixLab Machine Vision API. The client is a single PHP class which let you interact with the API server using the GET and POST HTTP methods.

For the full list of samples using this class, please refer to:

First Example: Blur all human faces:

require_once "pixlab.php";

 * Detect all human faces in a given image or video frame via `facedetect` and blur all of them via `mogrify`.
 * & for additional information.
# Target Image: Feel free to change to whatever image holding faces you want
$img = '';

$key = 'My_Pix_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;

if( count($faces) < 1 ){
	echo "No human faces were were detected on this picture\n";
	echo "Total number of detected faces: ".count($faces)."\n";
	echo "Censuring faces...\n";
	/Call mogrify (Only POST)/
	if( !$pix->post('mogrify',array('img' => $img,'cord' => $faces)) ){
		echo $pix->get_error_message();
		echo "Censured Faces: ".$pix->json->link."\n";

Second Example: Mimic Snapchat Filters

 * 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 & extract their landmark regions via facelandmarks & make a small Snapchat filter effect.
# Only three commands are actually needed in order to mimic the Snapchat filters effects:
# face landmarks:
# smart resize: 
# merge:        
# Optionally: blur, grayscale, oilpaint, etc. for cool background effects.

$img = '';

$pix = new Pixlab('My_Pix_Key');
/Grab the face landmarks first/
if( !$pix->get('facelandmarks',[
	'img' => $img
	]) ){
	echo $pix->get_error_message()."\n";

$total = count($pix->json->faces); # Total detected faces
print($total." faces were detected\n");
$snap = [];
# Iterate all over the detected faces
foreach ($pix->json->faces as $face){
	$cord = $face->rectangle;
	# Show the face coordinates 
	print ("Coordinates...\n");
	print ("\n\twidth: " . $cord->width . ' height: ' . $cord->height . ' x: ' . $cord->left .' y: ' . $cord->top);
	# Show landmarks:
	print ("\nLandmarks...\n");
	$landmarks = $face->landmarks;
	print ("\n\tNose: X: "       . $landmarks->nose->x      . ", Y: ".$landmarks->nose->y);
	print ("\n\tBottom Lip: X: " . $landmarks->bottom_lip->x. ", Y: ".$landmarks->bottom_lip->y);
	print ("\n\tTop Lip: X: "    . $landmarks->top_lip->x   . ", Y: ".$landmarks->top_lip->y);
	print ("\n\tChin: X: "       . $landmarks->chin->x      . ", Y: ".$landmarks->chin->y);
	print ("\n\tBone Center: X: "     . $landmarks->bone->center->x     . ", Y: ".$landmarks->bone->center->y);
	print ("\n\tBone Outer Left: X: " . $landmarks->bone->outer_left->x . ", Y: ".$landmarks->bone->outer_left->y);
	print ("\n\tBone Outer Right: X: ". $landmarks->bone->outer_right->x. ", Y: ".$landmarks->bone->outer_right->y);
	print ("\n\tBone Center: X: " . $landmarks->bone->center->x . ", Y: ".$landmarks->bone->center->y);
	print ("\n\tEye Pupil Left: X: " . $landmarks->eye->pupil_left->x . ", Y: ".$landmarks->eye->pupil_left->y);
	print ("\n\tEye Pupil Right: X: " . $landmarks->eye->pupil_right->x . ", Y: ".$landmarks->eye->pupil_right->y);
	print ("\n\tEye Left Brown Inner: X: " . $landmarks->eye->left_brow_inner->x . ", Y: ".$landmarks->eye->left_brow_inner->y);
	print ("\n\tEye Right Brown Inner: X: " . $landmarks->eye->right_brow_inner->x . ", Y: ".$landmarks->eye->right_brow_inner->y);
	print ("\n\tEye Left Outer: X: " . $landmarks->eye->left_outer->x . ", Y: ".$landmarks->eye->left_outer->y);
	print ("\n\tEye Right Outer: X: " . $landmarks->eye->right_outer->x . ", Y: ".$landmarks->eye->right_outer->y); 
	# More landmarks on the docs..
	# Pick the last face in this loop for the sack of simplicity. Refer to the sample set for a complete example
	$snap = $face;
# Make a quick Snapchat filter on top of the last detected face
if ($total < 1){
    # No faces were detected
# The flower crown to be composited on top of the target face
$flower = '';

# Resize the flower crown which is quite big right now to exactly the face width using smart resize.
print ("\nResizing the snap flower crown...\n");
if( !$pix->get('smartresize',[
	'img' => $flower,
	'width' => 20 + $snap->rectangle->width, # Face width
	'height' => 0 # Let Pixlab decide the best height for this picture
	]) ){
	echo $pix->get_error_message()."\n";
	$flower = $pix->json->link;
# Finally, Perform the composite operation
print ("Composite operation...\n");
if( !$pix->post('merge',[
	'src' => $img,
	'cord' => [
	array( /Array for each landmarks/
		'img' => $flower,
		'x' => $snap->landmarks->bone->outer_left->x,
		'y' => $snap->landmarks->bone->outer_left->y /Adjust for optimal effect/
	]]) ){
	echo $pix->get_error_message();
	 # Optionally call blur, oilpaint, grayscale for more stuff..
	print ("Snap Filter Effect: ".$pix->json->link);
echo "\n";

Third example: Blur an image or video frame based on its NSFW score

require_once "pixlab.php";

# Target Image: Change to any link (Possibly adult) you want or switch to POST if you want to upload your image directly.
# The target API endpoint we'll be using here: nsfw (
$img = '';

# Your PixLab key
$key = 'My_Pixlab_Key';

# Blur an image based on its NSFW score
$pix = new Pixlab($key);
/Invoke NSFW/
if( !$pix->get('nsfw',array('img' => $img)) ){
	echo $pix->get_error_message();
/Grab the NSFW score/
$score = $pix->json->score;
if( $score < 0.5 ){
	echo "No adult content were detected on this picture\n";
	echo "Censuring NSFW picture...\n";
	/Call blur with the highest possible radius and sigma/
	if( !$pix->get('blur',array('img' => $img,'rad' => 50,'sig' =>30)) ){
		echo $pix->get_error_message();
		echo "Censured Picture: ".$pix->json->link."\n";

Useful Links

  Files folder image Files  
File Role Description
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Plain text file pixlab.php Class Class source
Accessible without login Plain text file Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
This week:7
All time:8,478
This week:82Up