How to recognise adult content programmatically?

2019 Update

A lot has changed since this original answer way back in 2013, the main thing being machine learning. There are now a number of libraries and API's available for programmatically detecting adult content:

Google Cloud Vision API, which uses the same models Google uses for safe search.

NSFWJS uses TensorFlow.js claims to achieve ~90% accuracy and is open source under MIT license.

Yahoo has a solution called Open NSFW under the BSD 2 clause license.

2013 Answer

There is a JavaScript library called nude.js which is for this, although I have never used it. Here is a demo of it in use.

There is also PORNsweeper.

Another option is to "outsource" the moderation work using something like Amazon Mechanical Turk, which is a crowdsourced platform which "enables computer programs to co-ordinate the use of human intelligence to perform tasks which computers are unable to do". So you would basically pay a small amount per moderation item and have an outsourced actual human to moderate the content for you.

The only other solution I can think of is to make the images user moderated, where users can flag inappropriate posts/images for moderation, and if nobody wants to manually moderate them they can simply be removed after a certain number of flags.

Here are a few other interesting links on the topic:

  • What is the best way to programmatically detect porn images?

The example below does not give you 100% accurate results but it should help you a least a bit and works out of the box.

$url = '';
$data = json_decode(file_get_contents('' . $url));

if (@$data->success !== 1)
echo 'Contains nudity? ' . $data->nudity . '<br>';
echo 'Nudity percentage: ' . $data->nudity_percentage . '<br>';

If you are looking for an API-based solution, you may want to check out

It's an automated solution to detect things like adult content, violence, celebrities etc in images and videos.

Here is an example in PHP, using the SDK:

$client = new SightengineClient('YourApplicationID', 'YourAPIKey');

$output = $client>check('nudity')>image('');

The output will then return the classification:

{ "status": "success", "request": { "id": "req_VjyxevVQYXQZ1HMbnwtn", "timestamp": 1471762434.0244, "operations": 1 }, "nudity": { "raw": 0.000757, "partial": 0.000763, "safe": 0.999243 }, "media": { "id": "med_KWmB2GQZ29N4MVpVdq5K", "uri": "" } }

Have a look at the documentation for more details: (disclaimer: I work there)