Я сделал функцию, которая возвращает имя цвета. В парам. Я даю ширину массива цвет RGB.
Но когда я даю $ arr_input [157,183,198] в функцию, он возвращает затемненный. Цвет более синий, чем затемненный.
Что я здесь не так делаю?
function getColorNameByRgbColors($arr_input) {
// red will have a diff of: 5 + 1 + 2 groen will have: 250 + 254 + 2 blue is : 250 + 1 + 253
// based on --> http://www.w3.org/TR/SVG/types.html#ColorKeywords
$arr_colors = array(
'aliceblue' => array(240, 248, 255),
'antiquewit' => array(250, 235, 215),
'aqua' => array(0, 255, 255),
'aquamarine' => array(127, 255, 212),
'azure' => array(240, 255, 255),
'beige' => array(245, 245, 220),
'bisque' => array(255, 228, 196),
'zwart' => array(0, 0, 0),
'blanchedalmond' => array(255, 235, 205),
'blauuw' => array(0, 0, 255),
'blauuwviolet' => array(138, 43, 226),
'bruin' => array(165, 42, 42),
'burlywood' => array(222, 184, 135),
'cadetblue' => array(95, 158, 160),
'chartreuse' => array(127, 255, 0),
'chocolate' => array(210, 105, 30),
'coral' => array(255, 127, 80),
'cornflowerblue' => array(100, 149, 237),
'cornsilk' => array(255, 248, 220),
'crimson' => array(220, 20, 60),
'cyan' => array(0, 255, 255),
'darkblauuw' => array(0, 0, 139),
'darkcyan' => array(0, 139, 139),
'darkgoldenrod' => array(184, 134, 11),
'darkgray' => array(169, 169, 169),
'darkgroen' => array(0, 100, 0),
'darkgrey' => array(169, 169, 169),
'darkkhaki' => array(189, 183, 107),
'darkmagenta' => array(139, 0, 139),
'darkolivegroen' => array(85, 107, 47),
'darkorange' => array(255, 140, 0),
'darkorchid' => array(153, 50, 204),
'darkred' => array(139, 0, 0),
'darksalmon' => array(233, 150, 122),
'darkseagroen' => array(143, 188, 143),
'darkslateblue' => array(72, 61, 139),
'darkslategray' => array(47, 79, 79),
'darkslategrey' => array(47, 79, 79),
'darkturquoise' => array(0, 206, 209),
'darkviolet' => array(148, 0, 211),
'deeppink' => array(255, 20, 147),
'deepskyblue' => array(0, 191, 255),
'dimgray' => array(105, 105, 105),
'dodgerblue' => array(30, 144, 255),
'firebrick' => array(178, 34, 34),
'floralwit' => array(255, 250, 240),
'forestgroen' => array(34, 139, 34),
'fuchsia' => array(255, 0, 255),
'gainsboro' => array(220, 220, 220),
'ghostwit' => array(248, 248, 255),
'gold' => array(255, 215, 0),
'goldenrod' => array(218, 165, 32),
'gray' => array(128, 128, 128),
'grey' => array(128, 128, 128),
'groen' => array(0, 128, 0),
'groenyellow' => array(173, 255, 47),
'honeydew' => array(240, 255, 240),
'hotpink' => array(255, 105, 180),
'indianrood' => array(205, 92, 92),
'indigo' => array(75, 0, 130),
'ivory' => array(255, 255, 240),
'khaki' => array(240, 230, 140),
'lavender' => array(230, 230, 250),
'lavenderblush' => array(255, 240, 245),
'lawngroen' => array(124, 252, 0),
'lemonchiffon' => array(255, 250, 205),
'lichtblauw' => array(173, 216, 230),
'lichtcoral' => array(240, 128, 128),
'lichtcyan' => array(224, 255, 255),
'lichtgoldenrodyellow' => array(250, 250, 210),
'lichtgray' => array(211, 211, 211),
'lichtgroen' => array(144, 238, 144),
'lichtgrey' => array(211, 211, 211),
'lichtpink' => array(255, 182, 193),
'lichtsalmon' => array(255, 160, 122),
'lichtseagroen' => array(32, 178, 170),
'lichtskyblue' => array(135, 206, 250),
'lichtslategray' => array(119, 136, 153),
'lichtslategrey' => array(119, 136, 153),
'lichtsteelblue' => array(176, 196, 222),
'lichtyellow' => array(255, 255, 224),
'lime' => array(0, 255, 0),
'limegroen' => array(50, 205, 50),
'linen' => array(250, 240, 230),
'magenta' => array(255, 0, 255),
'kastanjebruin' => array(128, 0, 0),
'mediumaquamarine' => array(102, 205, 170),
'mediumblue' => array(0, 0, 205),
'mediumorchid' => array(186, 85, 211),
'mediumpurple' => array(147, 112, 219),
'mediumseagroen' => array(60, 179, 113),
'mediumslateblauw' => array(123, 104, 238),
'mediumspringgroen' => array(0, 250, 154),
'mediumturquoise' => array(72, 209, 204),
'mediumvioletred' => array(199, 21, 133),
'midnightblauw' => array(25, 25, 112),
'mintcream' => array(245, 255, 250),
'mistyrose' => array(255, 228, 225),
'moccasin' => array(255, 228, 181),
'navajowit' => array(255, 222, 173),
'navy' => array(0, 0, 128),
'oldlace' => array(253, 245, 230),
'olive' => array(128, 128, 0),
'olivedrab' => array(107, 142, 35),
'oranje' => array(255, 165, 0),
'orangerood' => array(255, 69, 0),
'orchid' => array(218, 112, 214),
'palegoldenrod' => array(238, 232, 170),
'palegroen' => array(152, 251, 152),
'paleturquoise' => array(175, 238, 238),
'palevioletred' => array(219, 112, 147),
'papayawhip' => array(255, 239, 213),
'peachpuff' => array(255, 218, 185),
'peru' => array(205, 133, 63),
'pink' => array(255, 192, 203),
'plum' => array(221, 160, 221),
'powderblue' => array(176, 224, 230),
'paars' => array(128, 0, 128),
'rood' => array(255, 0, 0),
'rosybrown' => array(188, 143, 143),
'royalblue' => array(65, 105, 225),
'saddlebrown' => array(139, 69, 19),
'salmon' => array(250, 128, 114),
'sandybrown' => array(244, 164, 96),
'seagroen' => array(46, 139, 87),
'seashell' => array(255, 245, 238),
'sienna' => array(160, 82, 45),
'silver' => array(192, 192, 192),
'skyblue' => array(135, 206, 235),
'slateblue' => array(106, 90, 205),
'slategray' => array(112, 128, 144),
'slategrey' => array(112, 128, 144),
'snow' => array(255, 250, 250),
'springgroen' => array(0, 255, 127),
'steelblue' => array(70, 130, 180),
'tan' => array(210, 180, 140),
'teal' => array(0, 128, 128),
'thistle' => array(216, 191, 216),
'tomato' => array(255, 99, 71),
'turquoise' => array(64, 224, 208),
'violet' => array(238, 130, 238),
'wheat' => array(245, 222, 179),
'wit' => array(255, 255, 255),
'witsmoke' => array(245, 245, 245),
'geel' => array(255, 255, 0),
'geelgroen' => array(154, 205, 50)
);
foreach($arr_colors as $key=>$color) {
// echo $arr_input[0] .'--'. $color[0] . '<br />';
$diff = abs($arr_input[0] - $color[0]) + abs($arr_input[1] - $color[1]) + abs($arr_input[2] - $color[2]);
$array[] = array('verschil' => $diff, 'kleur' => $key);
}
sort($array);
return $array[0]['kleur'];
}