Scan and block sensitive photos in Javascript

Cloudmersive
2 min readMar 9, 2020

--

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="https://cdn.cloudmersive.com/jsclient/cloudmersive-image-client.js"></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.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet