Photo Guardian

Documentation

This page explains how to integrate your application or website with Photo Guardian's image moderation services.


Create Target

Targets are endpoints used by external services (like yours) to interact with Photo Guardian. Targets are configured to consider a certain list of object classes, and to take a certain action. Targets support the following actions:

Analyze

Targets configured to take this action will simply analyze an image, and return the relevant detected objects in the following format:

[
    {
        "l": "object_name",
        "c": {
            "x": 100,
            "y": 100,
            "w": 75,
            "h": 125
        }
    },
    {
        "l": "object_name",
        "c": {
            "x": 350,
            "y": 150,
            "w": 200,
            "h": 200
        }
    }
]
            

Filter

Targets configured to take this action will analyze an image, and return a boolean value indicating whether the image is safe or not (based on whether any of the selected classes are present). When `is_safe` is `true`, the image does not contain any of the configured object types.

{"is_safe": false}

Censor

Targets configured to take this action will analyze an image, then censor any of the selected classes present with a black box. The image is returned in base64 format.

{"image": "data:image/jpg;base64,/9j/4cS5AIVSHz8yX3+roAPlVJD..."}

Test Target

To test a target, navigate to the testsubmit.php page. This page allows you to manually submit an image for sake of testing.

In the "Target" field, enter a target ID associated with one of the targets on the target management page.

In the "Image" field, enter a base64 encoded image string. On Linux, you can copy an image to your clipboard as base64 using the following command:

base64 TestImage.jpg | xclip -selection c -i

Leave the "Test" check-box enabled. This displays the output image on the submission page for conveinence, in addition to the computer-readable output typically returned.

After pressing submit, you should see the output from the request (depending on the configured action) after a few moments.


Use Target

Once you've created and configured a target, you can submit images to it from your service or application. To submit an image, send a POST request to the `/photoguardian/submit.php` endpoint with the following POST fields:
The target field contains the unique target identifer as defined when you created your target in Photo Guardian.
The image field contains the image data encoded in base64.

PHP Example

function image_to_base64($input_file) {
    $data = file_get_contents($input_file);
    $base64 = base64_encode($data);
    return $base64; // "/9j/ycSr05AoAPlVJ..."
}

$target = "3ab42e8b817a766dc8e4a637";
$image = image_to_base64("./test_image.jpg");

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL => "https://v0lttech.com/photoguardian/submit.php",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode(
        array(
            "target" => $target,
            "image" => $image
        )
    )
]);

$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);

if (strlen($error) > 0) {
    echo "Server error: " . $error;
    exit();
}
$analysis_results = json_decode($response, true);

print_r($analysis_results);