( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
exit();
set_time_limit(0) ;
include("includes/limittext.php");
include('Connections/videoondemand.php');
require("DbSql2.inc.php");
require("NewsSql2.inc.php");
$db = new NewsSQL();
include("protect.php");
/*var c = c.substring(1); // strip #
var rgb = parseInt(c, 16); // convert rrggbb to decimal
var r = (rgb >> 16) & 0xff; // extract red
var g = (rgb >> 8) & 0xff; // extract green
var b = (rgb >> 0) & 0xff; // extract blue
var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; // per ITU-R BT.709
if (luma < 40) {
// pick a different colour
}
*/class Color {
public $red = 0;
public $green = 0;
public $blue = 0;
public function __construct($red, $green, $blue)
{
$this->red = $red;
$this->green = $green;
$this->blue = $blue;
}
}
function calcualteHue($color) {
$red = $color->red / 255;
$green = $color->green / 255;
$blue = $color->blue / 255;
$min = min($red, $green, $blue);
$max = max($red, $green, $blue);
switch ($max) {
case 0:
// If the max value is 0.
$hue = 0;
break;
case $min:
// If the maximum and minimum values are the same.
$hue = 0;
break;
default:
$delta = $max - $min;
if ($red == $max) {
$hue = 0 + ($green - $blue) / $delta;
} elseif ($green == $max) {
$hue = 2 + ($blue - $red) / $delta;
} else {
$hue = 4 + ($red - $green) / $delta;
}
$hue *= 60;
if ($hue < 0) {
$hue += 360;
}
}
return $hue;
}
function rgbTohsv($color) {
$red = $color->red / 255;
$green = $color->green / 255;
$blue = $color->blue / 255;
$min = min($red, $green, $blue);
$max = max($red, $green, $blue);
switch ($max) {
case 0:
// If the max value is 0.
$hue = 0;
$saturation = 0;
$value = 0;
break;
case $min:
// If the maximum and minimum values are the same.
$hue = 0;
$saturation = 0;
$value = round($max, 4);
break;
default:
$delta = $max - $min;
if ($red == $max) {
$hue = 0 + ($green - $blue) / $delta;
} elseif ($green == $max) {
$hue = 2 + ($blue - $red) / $delta;
} else {
$hue = 4 + ($red - $green) / $delta;
}
$hue *= 60;
if ($hue < 0) {
$hue += 360;
}
$saturation = $delta / $max;
$value = round($max, 4);
}
return ['hue' => $hue, 'saturation' => $saturation, 'value' => $value];
}
function rgb_to_hex( $color ) {
$pattern = "/(\d{1,3})\,?\s?(\d{1,3})\,?\s?(\d{1,3})/";
// Only if it's RGB
if ( preg_match( $pattern, $color, $matches ) ) {
$r = $matches[1];
$g = $matches[2];
$b = $matches[3];
$color = sprintf("#%02x%02x%02x", $r, $g, $b);
}
return $color;
}
function renderColors($colors, $sortedBy) {
$color_width = 1;
$width = count($colors) * $color_width;
$height = 50;
$im = imagecreatetruecolor($width, $height);
$background_color = imagecolorallocate($im, 255, 255, 255);
$x = 0;
foreach ($colors as $colorObject) {
$color = imagecolorallocate($im, $colorObject->red, $colorObject->green, $colorObject->blue);
imagefilledrectangle($im, $x, 0, $x + $color_width,$height, $color);
$x = $x + $color_width;
}
imagepng($im, 'colors-' . $sortedBy . '.png');
imagedestroy($im);
}
$page =0;
$myColors = $db->getAllHexColors($page);
while ( list($key,$val)=each($myColors) ) {
$hex = "#".$val["hex"];
list($red, $green, $blue) = sscanf($hex, "#%02x%02x%02x");
$colors[] = new Color($red, $blue, $green);
/*usort($colors, function ($a, $b) {
$hsv1 = rgbTohsv($a);
$hsv2 = rgbTohsv($b);
return (($hsv1['hue'] + $hsv1['saturation'] + $hsv1['value']) < ($hsv2['hue'] + $hsv2['saturation'] + $hsv2['value'])) ? -1 : 1;
});*/
uasort($colors, function ($a, $b) {
return ((calcualteHue($a) ) < (calcualteHue($b))) ? -1 : 1;
});
/*usort($colors, function ($a, $b) {
$aValue['red'] = str_pad(dechex($a->red), 2, '0', STR_PAD_LEFT);
$aValue['green'] = str_pad(dechex($a->green), 2, '0', STR_PAD_LEFT);
$aValue['blue'] = str_pad(dechex($a->blue), 2, '0', STR_PAD_LEFT);
$bValue['red'] = str_pad(dechex($b->red), 2, '0', STR_PAD_LEFT);
$bValue['green'] = str_pad(dechex($b->green), 2, '0', STR_PAD_LEFT);
$bValue['blue'] = str_pad(dechex($b->blue), 2, '0', STR_PAD_LEFT);
$aValue = implode($aValue);
$bValue = implode($bValue);
return (($aValue ) < ($bValue)) ? -1 : 1;
});*/
}
/*
// Set up the ranges array.
$ranges = [];
foreach ($colors as $color) {
// Get the hue.
$hue = calcualteHue($color);
// Simplify the hue to create 12 segments.
$simplifiedHue = floor($hue / 30);
if (!isset($ranges[$simplifiedHue])) {
// Add the simplified hue to the ranges array if it doesn't exist.
$ranges[$simplifiedHue] = [];
}
// Add the color to the correct segment.
$ranges[$simplifiedHue][] = $color;
}
// Sort the ranges by their keys (the simplified hue).
ksort($ranges);
$newColors = [];
foreach ($ranges as $id => $colorRange) {
usort($colorRange, function ($a, $b) {
return (($a->red + $a->green + $a->blue) < ($b->red + $b->green + $b->blue)) ? -1 : 1;
});
$colors = array_merge($newColors, $colorRange);
}}
*/
/* print_r($colors);*/
$count =0;
foreach($colors as $key=>$value)
{
$count++;
$red = $value->red;
$red = $value->red;
$green = $value->green;
$blue = $value->blue;
$NewKey = $key +1;
$thergb = "$red,$blue,$green";
$hexed = rgb_to_hex($thergb);
if($count > 0 && $count < 230 )
{
echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'"> '.$hexed.' <br>black<br>'.$NewKey.'<br>'.$count.'</div>';
$brandid=$NewKey;
$color="black";
$tag= "1";
$added = $db->updateBrandHex($brandid,$color,$tag);
}
if($count > 231 && $count < 351 )
{
echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'">'.$hexed.' <br>reds<br>'.$NewKey.'<br>'.$count.'</div>';
$brandid=$NewKey;
$color="red";
$tag= "2";
$added = $db->updateBrandHex($brandid,$color,$tag);
}
if($count > 352 && $count < 521 )
{
echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'">'.$hexed.' <br>violet<br>'.$NewKey.'<br>'.$count.'</div>';
$brandid=$NewKey;
$color="violet";
$tag= "3";
$added = $db->updateBrandHex($brandid,$color,$tag);
}
if($count > 522 && $count < 1011 )
{
echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'">'.$hexed.' <br>blue<br>'.$NewKey.'<br>'.$count.'</div>';
$brandid=$NewKey;
$color="blue";
$tag= "4";
$added = $db->updateBrandHex($brandid,$color,$tag);
}
if($count > 1012 && $count < 1232 )
{
echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'">'.$hexed.' <br>cyan<br>'.$NewKey.'<br>'.$count.'</div>';
$brandid=$NewKey;
$color="cyan";
$tag= "5";
$added = $db->updateBrandHex($brandid,$color,$tag);
}
if($count > 1233 && $count < 1471 )
{
echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'">'.$hexed.' <br>green<br>'.$NewKey.'<br>'.$count.'</div>';
$brandid=$NewKey;
$color="green";
$tag= "6";
$added = $db->updateBrandHex($brandid,$color,$tag);
}
if($count > 1472 && $count < 1666 )
{
echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'">'.$hexed.' <br> yellow<br>'.$NewKey.'<br>'.$count.'</div>';
$brandid=$NewKey;
$color="yellow";
$tag= "7";
$added = $db->updateBrandHex($brandid,$color,$tag);
}
if($count > 1667 && $count < 1842 )
{
echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'">'.$hexed.' <br>orange<br>'.$NewKey.'<br>'.$count.'</div>';
$brandid=$NewKey;
$color="orange";
$tag= "8";
$added = $db->updateBrandHex($brandid,$color,$tag);
}
if($count > 1843 && $count < 2005 )
{
echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'">'.$hexed.' <br>red <br>'.$NewKey.'<br>'.$count.'</div>';
$brandid=$NewKey;
$color="red";
$tag= "9";
$added = $db->updateBrandHex($brandid,$color,$tag);
}
/* echo $div = ' <div style="height:50px; float:left; width:50px; font-size:10px; background-color:'.$hexed.'"><br>'.$NewKey.'<br>'.$count.'</div>';
*//* echo $key." - $div - $count<br>";*/
}
/*renderColors($colors, 'none');*/
?>