Example #1
0
<?php

require __DIR__ . '/vendor/autoload.php';
use NullNude\NullNude;
// Information about your API access.
$config = ['api_key' => 'YOUR_API_KEY', 'api_secret' => 'YOUR_API_SECRET'];
// Initialize the NullNude client.
$nullNude = new NullNude($config);
try {
    // Image can be either a local path or an external url.
    $image = "image_path_or_url";
    $moderateResource = $nullNude->moderate($image);
    // Check if the request returned a successful, populated resource.
    if ($moderateResource->isSuccessful()) {
        // Check if the image has been moderated,
        // moderate.json moderates the image only
        // if there was nudity present.
        if ($moderateResource->isModerated()) {
            // Download and save the moderated image.
            echo 'Moderated image url: ' . $moderateResource->getModeratedUrl();
        }
    }
    // Check if the image has been queued.
    if ($moderateResource->isQueued()) {
        // The image has been queued, you should check it later.
    }
    // Check if the request failed.
    if ($moderateResource->hasFailed()) {
        // The url might not be an image or there was an API error.
        echo $moderateResource->getErrorMessage();
    }
Example #2
0
<?php

require __DIR__ . '/vendor/autoload.php';
use NullNude\NullNude;
// Information about your API access.
$config = ['api_key' => 'YOUR_API_KEY', 'api_secret' => 'YOUR_API_SECRET'];
// Initialize the NullNude client.
$nullNude = new NullNude($config);
try {
    // Image can be either a local path or an external url.
    $image = "image_path_or_url";
    $roiResource = $nullNude->getRoi($image);
    // Check if the request returned a successful, populated resource.
    if ($roiResource->isSuccessful()) {
        // Get the array of regions of interest within the image.
        print_r($roiResource->getRoi());
    }
    // Check if the image has been queued.
    if ($roiResource->isQueued()) {
        // The image has been queued, you should check it later.
    }
    // Check if the request failed.
    if ($roiResource->hasFailed()) {
        // The url might not be an image or there was an API error.
        echo $roiResource->getErrorMessage();
    }
} catch (Exception $e) {
    print_r($e->getMessage());
}
Example #3
0
 /**
  * Test Curl error.
  */
 public function testCurlError()
 {
     $this->setExpectedException('\\NullNude\\Exceptions\\NullNudeException', 'Curl error.');
     $exec = '{  
         "status":"failure"
      }';
     $http = $this->getHttpMock($exec, 12345, 'Curl error.');
     $nullNude = new NullNude(['api_key' => $this->api_key, 'api_secret' => $this->api_secret], $http);
     $nullNude->checkNudity($this->image);
 }
Example #4
0
<?php

require __DIR__ . '/vendor/autoload.php';
use NullNude\NullNude;
// Information about your API access.
$config = ['api_key' => 'YOUR_API_KEY', 'api_secret' => 'YOUR_API_SECRET'];
// Initialize the NullNude client.
$nullNude = new NullNude($config);
try {
    // Image can be either a local path or an external url.
    $image = "image_path_or_url";
    $nudityResource = $nullNude->checkNudity($image);
    // Check if the request returned a successful, populated resource.
    if ($nudityResource->isSuccessful()) {
        // Check if the image has nuidty in it.
        if ($nudityResource->hasNudity()) {
            // Take action based on your confidence preference.
            echo 'Image nudity confidence: ' . $nudityResource->getNudityConfidence();
        }
        // Check if the image has covered nuidty in it.
        if ($nudityResource->hasCoveredNudity()) {
            // Take action based on your confidence preference.
            echo '<br> Image covered nudity confidence: ' . $nudityResource->getCoveredNudityConfidence();
        }
    }
    // Check if the image has been queued.
    if ($nudityResource->isQueued()) {
        // The image has been queued, you should check it later.
    }
    // Check if the request failed.
    if ($nudityResource->hasFailed()) {