<?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?!