#0: Search (255, 0, 0); Closest match: (161, 33, 17).
#0: Search (255, 0, 0); Closest match: <span style='border:2px solid rgb(161, 33, 17);'>(161, 33, 17)</span>.<br><?php
show_source('imgtest.php');exit;
function is_nsfw($rawfile){
//Modified from: https://www.php.net/manual/en/function.imagecolorclosest.php

// Start with an image and convert it to a palette-based image
$im = imagecreatefromjpeg($rawfile);
imagetruecolortopalette($im, false, 255);

// Search colors (RGBWB)
$colors = array(
    array(255,0,0),
/*    array(0,255,0),
    array(0,0,255),
    array(255,255,255),
    array(0,0,0)*/
);

// Loop through each search and find the closest color in the palette.
// Return the search number, the search RGB and the converted RGB match
foreach($colors as $id => $rgb)
{
    $result = imagecolorclosest($im, $rgb[0], $rgb[1], $rgb[2]);
    $result = imagecolorsforindex($im, $result);
    $result = "({$result['red']}, {$result['green']}, {$result['blue']})";

    echo "#$id: Search ($rgb[0], $rgb[1], $rgb[2]); Closest match: <span style='border:2px solid rgb$result;'>$result</span>.<br>";
}}

#Warning, this image is actual self harm, used to test the gore detector
is_nsfw('../u/Y-Y-deutsch-ich- kann-sehen-wie-meine-sehnen-sich-bewegen-aber-eine-stelle-habe ich schon-zugenäht-noch-zwei-stellen-jetzt-transl8 german-to-english-if-you-like.jpg');

#This is a control image, a "I love cat" quote in black and white
is_nsfw('Y-Y-360_F_437613381_uhAH4prMhYbj6Ow9cjk8Yj7UuVaOpXAZ.jpg');
?>