Frank786

Nudity API

Sep 27th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 1.57 KB | None | 0 0
  1. ?php
  2. require __DIR__ . '/vendor/autoload.php';
  3. use NullNude\NullNude;
  4. // Information about your API access.
  5. $config = [
  6.     'api_key'    => 'YOUR_API_KEY',
  7.     'api_secret' => 'YOUR_API_SECRET'
  8. ];
  9. // Initialize the NullNude client.
  10. $nullNude = new NullNude($config);
  11. try {
  12.     // Image can be either a local path or an external url.
  13.     $image = "image_path_or_url";
  14.     $nudityResource = $nullNude->checkNudity($image);
  15.    
  16.     // Check if the request returned a successful, populated resource.
  17.     if ( $nudityResource->isSuccessful() ) {
  18.         // Check if the image has nuidty in it.
  19.         if ( $nudityResource->hasNudity() ) {
  20.             // Take action based on your confidence preference.
  21.             echo 'Image nudity confidence: ' .
  22.                  $nudityResource->getNudityConfidence();
  23.         }
  24.        
  25.         // Check if the image has covered nuidty in it.
  26.         if ( $nudityResource->hasCoveredNudity() ) {
  27.             // Take action based on your confidence preference.
  28.             echo '<br> Image covered nudity confidence: ' .
  29.                  $nudityResource->getCoveredNudityConfidence();
  30.         }
  31.     }
  32.    
  33.     // Check if the image has been queued.
  34.     if ( $nudityResource->isQueued() ) {
  35.         // The image has been queued, you should check it later.
  36.     }
  37.    
  38.     // Check if the request failed.
  39.     if ( $nudityResource->hasFailed() ) {
  40.         // The url might not be an image or there was an API error.
  41.         echo $nudityResource->getErrorMessage();
  42.     }
  43. } catch ( Exception $e ) {
  44.     print_r($e->getMessage());
  45. }
Add Comment
Please, Sign In to add comment