Last active
April 3, 2021 00:29
-
-
Save symisc/bf383cf60a68cb3631e17aa641bb94fe to your computer and use it in GitHub Desktop.
Filter image uploads according to their NSFW score (PHP Example) - https://pixlab.io/cmd?id=nsfw, https://dev.to/unqlite_db/filter-image-uploads-according-to-their-nsfw-score-15be
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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