Home >Backend Development >PHP Tutorial >Use PHP to prevent users from uploading adult photos or nude photos, _PHP tutorial
In this tutorial, we will learn how to prevent users from uploading adult or nude photos through PHP.
I accidentally found a very useful class file on phpclasses.org, developed by Bakr Alsharif, which can help developers detect nude photos based on skin pixels.
It analyzes the colors used in different parts of an image and determines whether they match the hue of human skin color.
As a result of the analysis, it returns a score that reflects the likelihood that the image contains nudity.
Additionally, it can output the analyzed image, with pixels marked using a given color skin tone.
Currently it can analyze PNG, GIF and JPEG images.
PHP
The following shows how to use this PHP class.
Let’s start with the nf.php file that contains the nudity filter.
Next, create a new class called ImageFilter and put it in a variable called $filter.
Get the score of the image and put it into a $score variable.
If the image score is greater than or equal to 60%, then display a (alert) message.
Below is all the PHP code:
Markup language
We can use a basic HTML form to upload images.
Summary
Please remember that PHP cannot detect all nude images, so it is not completely reliable. I hope you find this useful.