Version 1.9.72 (Release Notes)


nsfwhttps://api.pixlab.io/nsfw

Description

Detect not suitable for work (i.e. nudity & adult) content in a given image or video frame. NSFW is of particular interest, if mixed with some media processing API endpoints like blur, encrypt or mogrify to censor images on the fly according to their nsfw score. This can help the developer automate things such as filtering user's uploads. See the example section for a concrete usage.

HTTP Methods

GET, POST

Request Parameters

Required

FieldsTypeDescription
imgURLInput image URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request.
keyStringYour PixLab API Key.

POST Request Body (If you plan to use POST instead of a simple GET request)

Allowed Content-Type:

multipart/form-data
application/json

Use multipart/form-data if you want to upload your image directly (refer to the sample set for a working example). If you are using JSON, then your image must be already uploaded somewhere. Call store if you want to upload an image before invoking this endpoint.

Response

application/json

This command always return a JSON object after each call. The field of interest here is the score value. The more this value approaches 1, the more your picture is highly nsfw. The following are the JSON fields returned in response body:

FieldsTypeDescription
statusIntegerStatus code 200 indicates success, any other code indicates failure.
scoreFloatNSFW score value which is set between 0 .. 1. The more this value approaches 1,the more your image is highly nsfw.
errorStringError message if status != 200.

Python Example

import requests
import json

# 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 key
key = 'Pixlab_Key'

# Censor an image according to its NSFW score
req = requests.get('https://api.pixlab.io/nsfw',params={'img':img,'key':key})
reply = req.json()
if reply['status'] != 200:
	print (reply['error'])
elif reply['score'] < 0.5 :
    print ("No adult content were detected on this picture")
else:
    # Highly NSFW picture
    print ("Censoring NSFW picture...")
    # Call blur with the highest possible radius and sigma
    req = requests.get('https://api.pixlab.io/blur',params={'img':img,'key':key,'rad':50,'sig':30})
    reply = req.json()
    if reply['status'] != 200:
        print (reply['error'])
    else:
        print ("Censored image: "+ reply['link'])

See Also