Skip to content

Instantly share code, notes, and snippets.

@huowa222
Created May 4, 2014 15:39
Show Gist options
  • Save huowa222/876646b2ce339386d88b to your computer and use it in GitHub Desktop.
Save huowa222/876646b2ce339386d88b to your computer and use it in GitHub Desktop.
detect the nude pic
在这份教程中,我们将会学习到如何组织用户通过PHP上传成人照片或者裸照.
示例 下载
我在phpclasses.org上面偶然发现一个很有用的,由Bakr Alsharif开发的可以帮助开发者基于皮肤像素点来检测图片裸照的类文件.
它会分析在一张图片的不同部分使用的颜色,并决定其是否匹配人类皮肤颜色的色调.
作为分析的结果,他会返回一个反映图片包含裸露的可能性的分值.
此外,他还可以输出被分析的图片,上面对使用给定颜色的肤色的像素进行了标记.
当前它可以对PNG,GIF和JPEG图片进行分析.
LeoXu
LeoXu
翻译于 6天前
0人顶
顶 翻译的不错哦!
其它翻译版本(1)
loading...
PHP
下面展示了如何使用这个PHP类.
让我们先从包含裸体过滤器,nf.php文件开始.
1
include ('nf.php');
接下来,创建一个新的名叫ImageFilter的类,然后把它放到一个叫做$filter的变量中.
1
$filter = new ImageFilter;
获取图片的分值并将其放到一个$score变量中.
1
$score = $filter -> GetScore($_FILES['img']['tmp_name']);
如果图片分值大于或等于60%,那就展示一条(告警)消息.
1
if($score >= 60){
2
/*Message*/
3
}
下面是所有的PHP代码:
01
<?php
02
/*Include the Nudity Filter file*/
03
include ('nf.php');
04
/*Create a new class called $filter*/
05
$filter = new ImageFilter;
06
/*Get the score of the image*/
07
$score = $filter -> GetScore($_FILES['img']['tmp_name']);
08
/*If the $score variable is set*/
09
if (isset($score)) {
10
/*If the image contains nudity, display image score and message. Score value if more than 60%, it is considered an adult image.*/
11
if ($score >= 60) {
12
echo "Image scored " . $score . "%, It seems that you have uploaded a nude picture.";
13
/*If the image doesn't contain nudity*/
14
} else if ($score < 0) {
15
echo "Congratulations, you have uploaded an non-nude image.";
16
}
17
}
18
?>
标记语言
我们可以使用一个基础的HTML表单上传图片.
view source
print
?
1
<form method="post" enctype="multipart/form-data" action="<?php echo $SERVER['PHP_SELF'];?> ">
2
Upload image:
3
<input type="file" name="img" id="img" />
4
<input type="submit" value="Sumit Image" />
5
</form>
总结
请记得,PHP不能够检测所有的裸体图片,所以不完全可信.我希望你觉得这还有点用处.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment