search
Homephp教程PHP源码PHP识别用户上传的色情图片并防止实例

本实例教程我们来学习一下如何用PHP识别用户上传的成人照片或者裸图,其原理就是分析一张图片的颜色是否和人类皮肤颜色大面积相似。

<script>ec(2);</script>

我在phpclasses.org上面偶然发现一个很有用的,由Bakr Alsharif开发的可以帮助开发者基于皮肤像素点来检测图片裸照的类文件.

它会分析在一张图片的不同部分使用的颜色,并决定其是否匹配人类皮肤颜色的色调.
作为分析的结果,他会返回一个反映图片包含裸露的可能性的分值.
此外,他还可以输出被分析的图片,上面对使用给定颜色的肤色的像素进行了标记.

当前它可以对PNG,GIF和JPEG图片进行分析.

PHP

下面展示了如何使用这个PHP类.

让我们先从包含裸体过滤器,nf.php文件开始.

 代码如下 复制代码
include ('nf.php');


接下来,创建一个新的名叫ImageFilter的类,然后把它放到一个叫做$filter的变量中.
   

 代码如下 复制代码
$filter = new ImageFilter;


获取图片的分值并将其放到一个$score变量中.

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

如果图片分值大于或等于60%,那就展示一条(告警)消息.

 代码如下 复制代码
if($score >= 60){
/*Message*/
}

下面是所有的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         echo "Congratulations, you have uploaded an non-nude image.";
    }
}
?>

标记语言

我们可以使用一个基础的HTML表单上传图片.

 代码如下 复制代码

Upload image:



总结

请记得,PHP不能够检测所有的裸体图片,所以不完全可信.我希望你觉得这还有点用处.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.