PHP Classes

Pixlab NSFW PHP Image Classifier: Check if images have nudity with Pixlab NSFW API

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 139 This week: 1All time: 9,215 This week: 560Up
Version License PHP version Categories
pixlab-php-nsfw 1.0.0Custom (specified...5PHP 5, Graphics, Web services, Artifi...
Description 

Author

This package can check if images have nudity with Pixlab NSFW API.

It can take the URL of the location of a given image file and send a HTTP request to Pixlab NSFW (Not Suitable For Work) Web service API.

This Web service uses machine vision analysis methods to determine if the uploaded image may contain adult content and returns a number that represents a score of the degree of probability that the image may contain people in appearing nude.

It may also return the image blurred in the areas that contain nudity.

Innovation Award
PHP Programming Innovation award nominee
August 2018
Number 9
Many sites allow users to upload picture files to be published. This may be problematic if the site is not able to determine if a picture contains unsuitable content for exhibiting to the public.

This package provides a solution to avoid that pictures with nudity be published.

It uses the Pixlab NSFW API to determine if a picture has those problems, as well can blur images showing parts of nude bodies.

Manuel Lemos
Picture of Symisc Systems
Name: Symisc Systems <contact>
Classes: 2 packages by
Country: South Africa South Africa
Age: ???
All time rank: 358119 in South Africa South Africa
Week rank: 411 Up4 in South Africa South Africa Up
Innovation award
Innovation award
Nominee: 2x

Example

<?php
/*
 * PixLab PHP Client which is just a single class PHP file without any dependency that is included in the package or
 * you can download the standalone client from at Github https://github.com/symisc/pixlab-php
 */
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, refer to the sample set for more info.
# The target API endpoint we'll be using here: nsfw (https://pixlab.io/cmd?id=nsfw).
$img = 'https://i.redd.it/oetdn9wc13by.jpg';

# 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();
    die;
}
/* Grab the NSFW score */
$score = $pix->json->score;
if(
$score < 0.5 ){
    echo
"No adult content were detected on this picture\n";
}else{
    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();
    }else{
        echo
"Censured Picture: ".$pix->json->link."\n";
    }
}
?>


Details

PHP NSFW Classifier

A single PHP Class to classify NSFW contents (i.e. Users image uploads) via the PixLab Machine Vision APIs - https://pixlab.io/cmd?id=nsfw

Requirements

PixLab PHP NSFW Classify Class works with PHP 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, and HHVM.

Install

To install PHP NSFW Class, simply:

$ composer require symisc/pixlab-php-nsfw

Or simply drop *pixlab.php* on your source tree and you're done!

Usage Example

<?php
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. 
$img = 'https://i.redd.it/oetdn9wc13by.jpg';

# Your PixLab key - Get one from https://pixlab.io/dashboard
$key = 'My_Pixlab_Key';

# Blur an image based on its NSFW score
$pix = new Pixlab($key);
/Invoke NSFW/
if( !$pix->get('nsfw',['img' => $img]) ){
	echo $pix->get_error_message();
	die;
}
/Grab the NSFW score/
$score = $pix->json->score;
if( $score < 0.5 ){
	echo "No adult content were detected on this picture\n";
}else{
	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();
	}else{
		echo "Censured Picture: ".$pix->json->link."\n";
	}
}
?>

PixLab Resources

PixLab Resources &amp; Sample Set. The Sample Set are practical usage, working code available in various programming languages intended to familiarize the reader with the PixLab API. For an introduction course, please refer to: * The PixLab API in 5 minutes or less. * List of API endpoints. * The PixLab API Reference Guide. * The PixLab Sample Set.

You?re welcome to copy/paste and run these examples to see the API in action.


  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
Accessible without login Plain text file nsfw_classify_example.php Example Example script
Plain text file pixlab.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:139
This week:1
All time:9,215
This week:560Up