Skip to content

Instantly share code, notes, and snippets.

@symisc
Last active April 3, 2021 00:29
Show Gist options
  • Save symisc/bf383cf60a68cb3631e17aa641bb94fe to your computer and use it in GitHub Desktop.
Save symisc/bf383cf60a68cb3631e17aa641bb94fe to your computer and use it in GitHub Desktop.
<?php
/*
* PixLab PHP Client which is just a single class PHP file without any dependency that you can get from Github
* https://github.com/symisc/pixlab-php
*/
require_once "pixlab.php";
# Target Image: Change to any link you want (Possibly adult) or switch to POST if you want to upload your image directly, refer to the sample set for more info.
$img = 'https://i.redd.it/oetdn9wc13by.jpg';
# Your PixLab API Key - Get yours from https://pixlab.io/dashboard
$key = 'PIXLAB_API_KEY';
# Blur an image according to 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 "Blurred Picture URL: ".$pix->json->link."\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment