Scan and block sensitive photos in Javascript

The merest whiff of NSFW content can bring down a storm of problems upon the unprepared. Any time you are dealing with user-submitted content, a proper filter is very important. If you don’t want to spend the next few hours or even days running Deep Learning to set this up yourself, then you came to the right place. Here is a demonstration of how to use one of our APIs to accomplish the same result almost instantly.

If we insert this script tag into our page between the head tags, our client will be imported.

<script src=""></script>

Once the importation has completed, we can then call our function using this block of code:

var CloudmersiveImageApiClient = require('cloudmersive-image-api-client');var defaultClient = CloudmersiveImageApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveImageApiClient.NsfwApi();var imageFile = "/path/to/file"; // File | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.nsfwClassify(imageFile, callback);

The API will process the image for us and return a score between 0 and 1 that will determine how likely the image contains racy imagery.

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store