Home >Backend Development >PHP Tutorial >Use PHP to prevent users from uploading adult photos or nude photos, _PHP tutorial

Use PHP to prevent users from uploading adult photos or nude photos, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:10:501151browse

Use PHP to prevent users from uploading adult photos or nude photos,

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.

Copy code The code is as follows:

include ('nf.php');

Next, create a new class called ImageFilter and put it in a variable called $filter.

Copy code The code is as follows:

$filter = new ImageFilter;

Get the score of the image and put it into a $score variable.

Copy code The code is as follows:

$score = $filter -> GetScore($_FILES['img']['tmp_name']);

If the image score is greater than or equal to 60%, then display a (alert) message.

Copy code The code is as follows:

if($score >= 60){
/*Message*/
}

Below is all the PHP code:

Copy code The code is as follows:

/*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.

Copy code The code is as follows:


Upload image:



Summary
Please remember that PHP cannot detect all nude images, so it is not completely reliable. I hope you find this useful.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/932483.htmlTechArticleUse PHP to prevent users from uploading adult photos or nude photos. In this tutorial, we will learn how to prevent Users upload adult photos or nude photos through PHP. I am in phpclasses.o...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn