违法图片检测

<?php
//
// +-----------------------------------+
// |        Image Filter v 1.0         |
// |      http://www.SysTurn.com       |
// +-----------------------------------+
//
//
//   This program is free software; you can redistribute it and/or modify
//   it under the terms of the ISLAMIC RULES and GNU Lesser General Public
//   License either version 2, or (at your option) any later version.
//
//   ISLAMIC RULES should be followed and respected if they differ
//   than terms of the GNU LESSER GENERAL PUBLIC LICENSE
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the license with this software;
//   If not, please contact support @ S y s T u r n .com to receive a copy.
//

CLASS ImageFilter
{                              #R  G  B
    var $colorA = 7944996;     #79 3B 24
    var $colorB = 16696767;    #FE C5 BF

    var $arA = array();
    var $arB = array();

    function ImageFilter()
    {
        $this->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; $i<=$x; $i++)
        {
            for($j=1; $j<=$y; $j++)
            {
                $color = @imagecolorat($img, $i, $j);
                if($color >= $this->colorA && $color <= $this->colorB)
                {
                    $color = array(‘R‘=> ($color >> 16) & 0xFF, ‘G‘=> ($color >> 8) & 0xFF, ‘B‘=> $color & 0xFF);
                    if($color[‘G‘] >= $this->arA[‘G‘] && $color[‘G‘] <= $this->arB[‘G‘] && $color[‘B‘] >= $this->arA[‘B‘] && $color[‘B‘] <= $this->arB[‘B‘])
                    {
                        if($i >= $zPoints[0] && $j >= $zPoints[1] && $i <= $zPoints[2] && $j <= $zPoints[3])
                        {
                            $score += 3;
                        }
                        elseif($i <= $xPoints[0] || $i >=$xPoints[5] || $j <= $yPoints[0] || $j >= $yPoints[5])
                        {
                            $score += 0.10;
                        }
                        elseif($i <= $xPoints[0] || $i >=$xPoints[4] || $j <= $yPoints[0] || $j >= $yPoints[4])
                        {
                            $score += 0.40;
                        }
                        else
                        {
                            $score += 1.50;
                        }
                    }
                }
            }
        }

        imagedestroy($img);

        $score = sprintf(‘%01.2f‘, ($score * 100) / ($x * $y));
        if($score > 100) $score = 100;
        return $score;
    }

    function GetScoreAndFill($image, $outputImage)
    {
        $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; $i<=$x; $i++)
        {
            for($j=1; $j<=$y; $j++)
            {
                $color = imagecolorat($img, $i, $j);
                if($color >= $this->colorA && $color <= $this->colorB)
                {
                    $color = array(‘R‘=> ($color >> 16) & 0xFF, ‘G‘=> ($color >> 8) & 0xFF, ‘B‘=> $color & 0xFF);
                    if($color[‘G‘] >= $this->arA[‘G‘] && $color[‘G‘] <= $this->arB[‘G‘] && $color[‘B‘] >= $this->arA[‘B‘] && $color[‘B‘] <= $this->arB[‘B‘])
                    {
                        if($i >= $zPoints[0] && $j >= $zPoints[1] && $i <= $zPoints[2] && $j <= $zPoints[3])
                        {
                            $score += 3;
                            imagefill($img, $i, $j, 16711680);
                        }
                        elseif($i <= $xPoints[0] || $i >=$xPoints[5] || $j <= $yPoints[0] || $j >= $yPoints[5])
                        {
                            $score += 0.10;
                            imagefill($img, $i, $j, 14540253);
                        }
                        elseif($i <= $xPoints[0] || $i >=$xPoints[4] || $j <= $yPoints[0] || $j >= $yPoints[4])
                        {
                            $score += 0.40;
                            imagefill($img, $i, $j, 16514887);
                        }
                        else
                        {
                            $score += 1.50;
                            imagefill($img, $i, $j, 512);
                        }
                    }
                }
            }
        }
        imagejpeg($img, $outputImage);

        imagedestroy($img);

        $score = sprintf(‘%01.2f‘, ($score * 100) / ($x * $y));
        if($score > 100) $score = 100;
        return $score;
    }

    function _GetImageResource($image, &$x, &$y)
    {
        $info = GetImageSize($image);

        $x = $info[0];
        $y = $info[1];

        switch( $info[2] )
        {
            case IMAGETYPE_GIF:
                return @ImageCreateFromGif($image);

            case IMAGETYPE_JPEG:
                return @ImageCreateFromJpeg($image);

            case IMAGETYPE_PNG:
                return @ImageCreateFromPng($image);

            default:
                return false;
        }
    }
}

?>

<?php
//error_reporting(0);

$error = ‘‘;
var_dump($_FILES);
if ($_FILES) {
    /*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‘]);

    var_dump($score);

    /*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 = "<b>Image scored " . $score . "%, It seems that you have uploaded a nude picture.</b>";
        /*If the image doesn‘t contain nudity*/
        } else if ($score < 0) {
            $error = "<b>Congratulations, you have uplaoded an non-nude image.</b>";
        }
    }
}
?>

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8" />
    <head>
        <title>Nudity Filter - RRPowered</title>
    </head>
    <body>
        <?php echo $error;?>
        <form method="post" enctype="multipart/form-data" action="/NudityFilter/index.php">
        Upload image:
        <input type="file" name="img" id="img" />
        <br />
        <input type="submit" value="Sumit Image" />
        </form>
    </body>
</html>

  

时间: 2024-08-02 22:31:15

违法图片检测的相关文章

图片流量节省大杀器:基于CDN的sharpP自适应图片技术实践

阅读原文,更多技术干货,请访问腾云阁. 目前移动端运营素材大部分依赖图片,基于对图片流量更少,渲染速度更快的诉求,我们推动CDN,X5内核,即通产品部共同推出了一套业务透明,无痛接入的CDN图片优化方案:基于CDN的sharpP自适应图片无痛接入方案.据统计效果可在原图基础上节省60%-75%的流量,比之前webP无痛接入方案效果提升40%-50%,减少流量的同时提高页面渲染速度,提升用户体验. 效果数据 目前手Q增值业务:VIP中心.游戏中心.动漫.游戏公会.特别关心 以及增值渠道的QQ钱包,

图片上传类与加密解密

php图片上传类 <?php //引入config_app全局变量 include ini_get("yaf.library") ."/../config/application/global.php"; include 'Image.php'; include 'Aes.php'; //获取链接过来的参数 $format = isset($_GET['__format'])?$_GET['__format']:"json"; switch

图片加载错误处理

<script src="../public/js/jquery-1.8.3.js"></script> <title>预加载</title> <script type="text/javascript"> $(document).ready(function(){ $("img").each(function(i,e){ var imgsrc=$(e).attr("src&q

视频人脸检测——Dlib版(六)

往期目录 视频人脸检测--Dlib版(六) OpenCV添加中文(五) 图片人脸检测--Dlib版(四) 视频人脸检测--OpenCV版(三) 图片人脸检测--OpenCV版(二) OpenCV环境搭建(一) 更多更新,欢迎访问我的github:https://github.com/vipstone/faceai 前言 Dlib的人脸识别要比OpenCV精准很多,一个是模型方面的差距,在一方面和OpenCV的定位有关系,OpenCV是一个综合性的视觉处理库,既然这么精准,那就一起赶快来看吧. 视

YOLOv3模型识别车位图片的测试报告(节选)

1,YOLOv3模型简介 YOLO能实现图像或视频中物体的快速识别.在相同的识别类别范围和识别准确率条件下,YOLO识别速度最快. 官网:https://pjreddie.com/darknet/yolo/ 知乎:https://zhuanlan.zhihu.com/p/25236464 YOLO有多种模型,包括V1,V2,V3,其中V3识别准确率最高,但对硬件要求也高.还有tiny模型.也可针对特定识别物体类别进行训练,获得应用需要的专用模型. 本次测试采用V3模型.对实际车场图片进行批量检测

使用nginx+lua+GraphicsMagick实现图片自动 裁剪

在做网站尤其是以内容为主的过程中,常常会遇到一张图片各种地方都要引用,且每个引用的地方要求的图片尺寸都不一样的.一般中大型的网站都会对这一类的图片做自动裁剪功能.本文介绍在centos6操作系统上,采用nginx.lua和GraphicsMagick工具简单实现图片的自动裁剪功能.其中nginx负责展示图片和调度lua脚本,GraphicsMagick负责对原图进行裁剪. 一.基础软件包安装groupadd wwwuseradd -g www www -s /bin/falseyum -y in

手把手教你用深度学习做物体检测(六):YOLOv2介绍

本文接着上一篇<手把手教你用深度学习做物体检测(五):YOLOv1介绍>文章,介绍YOLOv2在v1上的改进.有些性能度量指标术语看不懂没关系,后续会有通俗易懂的关于性能度量指标的介绍文章. YOLOv2 论文:< YOLO9000: Better, Faster, Stronger> 地址:  https://arxiv.org/pdf/1612.08242v1.pdf yolov2和v1的区别 引入了Batch Normalization  有一定的正则化效果,可以减轻过拟合,

大中型 UGC 平台的反垃圾(anti-spam)工作

本文来自网易云社区 随着互联网技术的日渐发展,相继诞生了垂直社区.社交平台.短视频应用.网络直播等越来越多样的产品.但在内容爆炸式增长的同时,海量UGC中也夹杂着各种违规垃圾信息,包括垃圾广告.诈骗信息.色情信息等.违法违规信息等,让不少互联网产品和广大网民深受其害. 浅谈反垃圾实现 有人会把反垃圾比喻成博弈的战场,反垃圾是一场团队战,跟灰黑产是一场成本的较量,在这场博弈中,胜利的关键依赖于高质量团队持久的协作. 反垃圾在实现方法上,其核心思想是在载体中提取数据后进行特征匹配得出分类结果的过程.

网易云易盾CTO朱浩齐:我们是如何用AI赋能内容安全?

欢迎访问网易云社区,了解更多网易技术产品运营经验. 5月19日,LiveVideoStack携手网易云易盾,共同打造了"娱乐多媒体开发应用实践"专题,帮助开发者和泛娱乐平台运营人员,提升技术能力,突破难点,拓展思路与视野. 在专题论坛中,网易云易盾CTO朱浩齐分享了<AI赋能的内容安全技术实践>主题内容,从策略.技术.产品三个方面,详细介绍了网易在内容安全系统构建方面的实践经验,包括如何建立对有害信息精细明确的审核体系和应急响应机制,如何采用基于自然语言.深度学习技术的智能