您好,欢迎访问一九零五行业门户网

PHP自动识别用户上传不雅图片并发邮箱提示

在这份教程中,我们将会学习到如何阻止用户通过上传不雅图片,这个测试了一下只有一点作用,但人家真的要做了估计也没有办法了,下面来给大家介绍解决办法吧.
我在phpclasses.org上面偶然发现一个很有用的,由bakr alsharif开发的可以帮助开发者基于皮肤像素点来检测图片的类文件.
它会分析在一张图片的不同部分使用的颜色,并决定其是否匹配人类皮肤颜色的色调,作为分析的结果,他会返回一个反映图片包含xx露的可能性的分值,此外,他还可以输出被分析的图片,上面对使用给定颜色的肤色的像素进行了标记,当前它可以对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代码:
index.php
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 consider as adult image.*/ if ($score >= 60){ $error = image scored . $score . %, it seems that you have uploaded a nude picture.; /*if the image doesn't contain nudity*/ } else if ($score nudity filter - rrpowered upload image:

nf.php
ara['r'] = ($this->colora >> 16) & 0xff; $this->ara['g'] = ($this->colora >> 8) & 0xff; $this->ara['b'] = $this->colora & 0xff; $this->arb['r'] = ($this->colorb >> 16) & 0xff; $this->arb['g'] = ($this->colorb >> 8) & 0xff; $this->arb['b'] = $this->colorb & 0xff; } function getscore($image) { $x = 0; $y = 0; $img = $this->_getimageresource($image, $x, $y); if(!$img) return false; $score = 0; $xpoints = array($x/8, $x/4, ($x/8 + $x/4), $x-($x/8 + $x/4), $x-($x/4), $x-($x/8)); $ypoints = array($y/8, $y/4, ($y/8 + $y/4), $y-($y/8 + $y/4), $y-($y/8), $y-($y/8)); $zpoints = array($xpoints[2], $ypoints[1], $xpoints[3], $y); for($i=1; $icolora && $color colorb) { $color = array('r'=> ($color >> 16) & 0xff, 'g'=> ($color >> 8) & 0xff, 'b'=> $color & 0xff); if($color['g'] >= $this->ara['g'] && $color['g'] arb['g'] && $color['b'] >= $this->ara['b'] && $color['b'] arb['b']) { if($i >= $zpoints[0] && $j >= $zpoints[1] && $i _getimageresource($image, $x, $y); if(!$img) return false; $score = 0; $xpoints = array($x/8, $x/4, ($x/8 + $x/4), $x-($x/8 + $x/4), $x-($x/4), $x-($x/8)); $ypoints = array($y/8, $y/4, ($y/8 + $y/4), $y-($y/8 + $y/4), $y-($y/8), $y-($y/8)); $zpoints = array($xpoints[2], $ypoints[1], $xpoints[3], $y); for($i=1; $icolora && $color colorb) { $color = array('r'=> ($color >> 16) & 0xff, 'g'=> ($color >> 8) & 0xff, 'b'=> $color & 0xff); if($color['g'] >= $this->ara['g'] && $color['g'] arb['g'] && $color['b'] >= $this->ara['b'] && $color['b'] arb['b']) { if($i >= $zpoints[0] && $j >= $zpoints[1] && $i
标记语言:我们可以使用一个基础的html表单上传图片,代码如下:
请记得,php不能够检测所有的图片,所以不完全可信,我希望你觉得这还有点用处.
教程地址:
欢迎转载!但请带上文章地址^^
其它类似信息

推荐信息