Prevent Uploads of Adult or Nude Pictures Using PHP

nude
In this tutorial, we will learn how to prevent adult or nude images from being uploaded using PHP.
DemoDownload

I stumbled across an interesting and useful class file in phpclasses.org that helps to detect image nudity based on skin pixel score developed by Bakr Alsharif.

It analyses the colors used in different sections of an image to determine whether those colors match the human skin color tones.

As result of the analysis, it returns a score value that reflects the probability of the image to contain nudity.

Additionally, it can output the analyzed image by marking the pixel with a colored skin tone using a given color.

Currently it can analyze images in the PNG, GIF and JPEG images.

The PHP

Below is how to use this PHP class. Let’s start by including the nudity filter, the nf.php file.

Next, create an instance of the class called ImageFilter and store in a variable called $filter.

Get the image score and put in into a variable $score.

If the image score is greater than or equal to 60%, show a message.

Here is the whole PHP code below:

The Markup

We use a basic HTML form to upload the image.

Conclusion

Keep in mind, this PHP class cannot detect all nude images and is not completely reliable. I hope you find this useful.

BarrettDemoDownload

Tagged with:

View all contributions by

Website: http://rrpowered.com

Related Articles

Stay connected with us

Add us on Google+

Follow us on Facebook

Follow us on Twitter

Get updates via RSS

Get email updates

FEEDBACK1

  1. Sebastien Barre
    1

    These “skin detection” libraries have very high occurrences of false positives (in other words they will reject lots of images that might not contain any nudity).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">