PHP Detection vulgar Picture-_-!

Source: Internet
Author: User
<?php/** * PHP Check vulgar picture * Author: Book Beetle fish */if ($argc = = 2) {$file _name = $argv [1];if (Is_file ($file _name)) {//file exists $image = Openimage File ($file _name); $rate = Testskin ($image [' Image_handle '], $image [' width '], $image [' height ']); if ($rate > 0.3) {echo "$file _name seems to be a vulgar picture. Color ratio: $rate/n";} else {echo "$file _name seems to be not a vulgar picture. Color ratio: $rate/n";}} else {echo "$file _name can ' t be find!/n";}} Else{echo "Usage:testskin.php filename/n";} function Openimagefile ($file _name) {list ($width, $height, $type, $attr) = getimagesize ($file _name), switch ($type) {case 2: $image _handle = imagecreatefromjpeg ($file _name); Return Array (' image_handle ' = $image _handle, ' width ' = $width, ' height ' and $height);} function Testskin ($image _handle, $width, $height) {$skin _pix = 0;for ($w =0; $w < $width; $w + +) {for ($h =0; $h < $height; $h + +) {//verify picture $rgb = Imagecolorat ($image _handle, $w, $h); $r = ($rgb >>) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $Y =0.299* $r +0.587* $g +0.114* $b; $Cb =0.564* ($b-$Y) +128; $Cr =0.713* ($r-$Y) +128;if ($Cb >= && $Cb <= 117 && $Cr >= $ && $Cr <= 168) {$skin _pix + +;}}} $skin _rate = $skin _pix/($width * $height); return $skin _rate;}? >

Requires the support of GD library. Open the GD extension inside the php.ini.

I suddenly have a good idea ... Combine this test with the previous crawler. Is it convenient to look for a picture?!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.