This article mainly introduces how to use PHP to prevent users from uploading adult photos or nude photos. The methods and ideas are very good and recommended to you. For more information, see.
This article mainly introduces how to use PHP to prevent users from uploading adult photos or nude photos. The methods and ideas are very good and recommended to you. For more information, see.
In this tutorial, we will learn how to prevent users from uploading adult photos or nude photos through PHP.
On phpclasses.org, I accidentally found a very useful file. Developed by Bakr Alsharif, it can help developers detect bare image files based on skin pixels.
It analyzes the colors used in different parts of an image and determines whether it matches the human skin color.
As a result of the analysis, the system returns a score that reflects the possibility of image exposure.
In addition, he can output the analyzed image and mark the pixels with the color given.
Currently, it can analyze PNG, GIF, and JPEG images.
PHP
The following shows how to use this PHP class.
Let's start with the inclusion of the native filter, nf. php file.
The Code is as follows:
Include ('nf. php ');
Next, create a new class named ImageFilter and put it in a variable named $ filter.
The Code is as follows:
$ Filter = new ImageFilter;
Get the image score and put it in a $ score variable.
The Code is as follows:
$ Score = $ filter-> GetScore ($ _ FILES ['img '] ['tmp _ name']);
If the image score is greater than or equal to 60%, an alarm message is displayed.
The Code is as follows:
If ($ score> = 60 ){
/* Message */
}
Below are all the PHP code:
The Code is as follows:
<? Php
/* Include the Nudity Filter file */
Include ('nf. php ');
/* Create a new class called $ filter */
$ Filter = new ImageFilter;
/* Get the score of the image */
$ Score = $ filter-> GetScore ($ _ FILES ['img '] ['tmp _ name']);
/* If the $ score variable is set */
If (isset ($ score )){
/* If the image contains nudity, display image score and message. Score value if more than 60%, it is considered an adult image .*/
If ($ score> = 60 ){
Echo "Image scored". $ score. "%, It seems that you have uploaded a nude picture .";
/* If the image doesn' t contain nudity */
} Else if ($ score <0 ){
Echo "Congratulations, you have uploaded an non-nude image .";
}
}
?>
Markup Language
We can use a basic HTML form to upload images.
The Code is as follows:
Summary
Please remember that PHP cannot detect all naked pictures, so it is not completely credible. I hope you will find this useful.