43 'aliceblue' =>
'f0f8ff',
44 'antiquewhite' =>
'faebd7',
46 'aquamarine' =>
'7fffd4',
51 'blanchedalmond' =>
'ffebcd',
53 'blueviolet' =>
'8a2be2',
55 'burlywood' =>
'deb887',
56 'cadetblue' =>
'5f9ea0',
57 'chartreuse' =>
'7fff00',
58 'chocolate' =>
'd2691e',
60 'cornflowerblue' =>
'6495ed',
61 'cornsilk' =>
'fff8dc',
62 'crimson' =>
'dc143c',
64 'darkblue' =>
'00008b',
65 'darkcyan' =>
'008b8b',
66 'darkgoldenrod' =>
'b8860b',
67 'darkgray' =>
'a9a9a9',
68 'darkgreen' =>
'006400',
69 'darkkhaki' =>
'bdb76b',
70 'darkmagenta' =>
'8b008b',
71 'darkolivegreen' =>
'556b2f',
72 'darkorange' =>
'ff8c00',
73 'darkorchid' =>
'9932cc',
74 'darkred' =>
'8b0000',
75 'darksalmon' =>
'e9967a',
76 'darkseagreen' =>
'8fbc8f',
77 'darkslateblue' =>
'483d8b',
78 'darkslategray' =>
'2f4f4f',
79 'darkturquoise' =>
'00ced1',
80 'darkviolet' =>
'9400d3',
81 'deeppink' =>
'ff1493',
82 'deepskyblue' =>
'00bfff',
83 'dimgray' =>
'696969',
84 'dodgerblue' =>
'1e90ff',
85 'firebrick' =>
'b22222',
86 'floralwhite' =>
'fffaf0',
87 'forestgreen' =>
'228b22',
88 'fuchsia' =>
'ff00ff',
89 'gainsboro' =>
'dcdcdc',
90 'ghostwhite' =>
'f8f8ff',
92 'goldenrod' =>
'daa520',
95 'greenyellow' =>
'adff2f',
96 'honeydew' =>
'f0fff0',
97 'hotpink' =>
'ff69b4',
98 'indianred' =>
'cd5c5c',
102 'lavender' =>
'e6e6fa',
103 'lavenderblush' =>
'fff0f5',
104 'lawngreen' =>
'7cfc00',
105 'lemonchiffon' =>
'fffacd',
106 'lightblue' =>
'add8e6',
107 'lightcoral' =>
'f08080',
108 'lightcyan' =>
'e0ffff',
109 'lightgoldenrodyellow' =>
'fafad2',
110 'lightgreen' =>
'90ee90',
111 'lightgrey' =>
'd3d3d3',
112 'lightpink' =>
'ffb6c1',
113 'lightsalmon' =>
'ffa07a',
114 'lightseagreen' =>
'20b2aa',
115 'lightskyblue' =>
'87cefa',
116 'lightslategray' =>
'778899',
117 'lightsteelblue' =>
'b0c4de',
118 'lightyellow' =>
'ffffe0',
120 'limegreen' =>
'32cd32',
122 'magenta' =>
'ff00ff',
123 'maroon' =>
'800000',
124 'mediumaquamarine' =>
'66cdaa',
125 'mediumblue' =>
'0000cd',
126 'mediumorchid' =>
'ba55d3',
127 'mediumpurple' =>
'9370db',
128 'mediumseagreen' =>
'3cb371',
129 'mediumslateblue' =>
'7b68ee',
130 'mediumspringgreen' =>
'00fa9a',
131 'mediumturquoise' =>
'48d1cc',
132 'mediumvioletred' =>
'c71585',
133 'midnightblue' =>
'191970',
134 'mintcream' =>
'f5fffa',
135 'mistyrose' =>
'ffe4e1',
136 'moccasin' =>
'ffe4b5',
137 'navajowhite' =>
'ffdead',
139 'oldlace' =>
'fdf5e6',
141 'olivedrab' =>
'6b8e23',
142 'orange' =>
'ffa500',
143 'orangered' =>
'ff4500',
144 'orchid' =>
'da70d6',
145 'palegoldenrod' =>
'eee8aa',
146 'palegreen' =>
'98fb98',
147 'paleturquoise' =>
'afeeee',
148 'palevioletred' =>
'db7093',
149 'papayawhip' =>
'ffefd5',
150 'peachpuff' =>
'ffdab9',
154 'powderblue' =>
'b0e0e6',
155 'purple' =>
'800080',
157 'rosybrown' =>
'bc8f8f',
158 'royalblue' =>
'4169e1',
159 'saddlebrown' =>
'8b4513',
160 'salmon' =>
'fa8072',
161 'sandybrown' =>
'f4a460',
162 'seagreen' =>
'2e8b57',
163 'seashell' =>
'fff5ee',
164 'sienna' =>
'a0522d',
165 'silver' =>
'c0c0c0',
166 'skyblue' =>
'87ceeb',
167 'slateblue' =>
'6a5acd',
168 'slategray' =>
'708090',
170 'springgreen' =>
'00ff7f',
171 'steelblue' =>
'4682b4',
174 'thistle' =>
'd8bfd8',
175 'tomato' =>
'ff6347',
176 'turquoise' =>
'40e0d0',
177 'violet' =>
'ee82ee',
180 'whitesmoke' =>
'f5f5f5',
181 'yellow' =>
'ffff00',
182 'yellowgreen' =>
'9acd32'
185 if (is_null($name)) {
188 return (empty($palette[$name])) ?
'' : $palette[$name];
205 public static function rgb($r, $g, $b, $zero_to_one_range=
true)
208 if ($zero_to_one_range) {
210 'r' => (($r >= 0) ? (($r <= 255) ? (
double) ( ((
double)$r) / 255.0) : 1) : 0),
211 'g' => (($g >= 0) ? (($g <= 255) ? (
double) ( ((
double)$g) / 255.0) : 1) : 0),
212 'b' => (($b >= 0) ? (($b <= 255) ? (
double) ( ((
double)$b) / 255.0) : 1) : 0)
216 'r' => (($r >= 0) ? (($r <= 255) ? ((
int) $r) : 255) : 0),
217 'g' => (($g >= 0) ? (($g <= 255) ? ((
int) $g) : 255) : 0),
218 'b' => (($b >= 0) ? (($b <= 255) ? ((
int) $b) : 255) : 0)
237 public static function cmyk($c, $m, $y, $k)
240 'c' => (($c >= 0) ? (($c <= 100) ? (
double) ( ((
double)$c) / 100.0) : 1) : 0),
241 'm' => (($g >= 0) ? (($m <= 100) ? (
double) ( ((
double)$m) / 100.0) : 1) : 0),
242 'y' => (($y >= 0) ? (($y <= 100) ? (
double) ( ((
double)$y) / 100.0) : 1) : 0),
243 'k' => (($k >= 0) ? (($k <= 100) ? (
double) ( ((
double)$k) / 100.0) : 1) : 0)
262 public static function hsv($h,$s,$v)
264 return Array(
'h' => $h,
's' => $s/100,
'v' => $v/100);
284 $output = Array(
'r' => 0,
'g' => 0,
'b' => 0);
287 $output[
'r'] = 1 - ($c + $k);
292 $output[
'g'] = 1 - ($m + $k);
297 $output[
'b'] = 1 - ($y + $k);
339 $output = Array(
'c' => $c,
'm' => $m,
'y' => $y,
'k' => $k);
359 if ($input[
'c'] < $input[
'm'])
364 if ($input[
'y'] < $min)
367 if (($min + $input[
'k']) > 1)
368 $min = 1 - $input[
'k'];
389 return Array(
'r' => (1 - $i[
'r']),
'g' => (1 - $i[
'g']),
'b' => (1 - $i[
'b']));
405 return sprintf(
'%02x%02x%02x', $input[
'r'] * 255, $input[
'g'] * 255, $input[
'b'] * 255);
420 return sprintf(
'%06x', $input);
435 public static function intToRgb($input, $zero_to_one_range=
true)
437 $b = min($input % 256, 255);
438 $g = min(($input >> 8) % 256, 255);
439 $r = min($input >> 16, 255);
440 return Colour::rgb($r, $g, $b, $zero_to_one_range);
456 $input = preg_replace(
'/^#/',
'', strtolower($input));
457 if (sprintf(
'%06x',hexdec($input)) != $input) {
477 public static function htmlToRgb($input, $zero_to_one_range=
true)
481 hexdec(substr($input, 0, 2)),
482 hexdec(substr($input, 2, 2)),
483 hexdec(substr($input, 4, 2)),
534 $r = max(0,min(1,$input[
'r']));
535 $g = max(0,min(1,$input[
'g']));
536 $b = max(0,min(1,$input[
'b']));
537 $min = min($r,$g,$b);
538 $max = max($r,$g,$b);
540 return Array(
'h' => -1,
's' => 0,
'v' => 0);
542 $delta = $max - $min;
546 return Array(
'h' => -1,
's' => 0,
'v' => $v);
550 $h = ($g - $b) / $delta;
551 } elseif ($g == $max) {
553 $h = 2 + ($b - $r) / $delta;
556 $h = 4 + ($r - $g) / $delta;
559 if ($h < 0) $h += 360;
560 return Array(
'h' => $h,
's' => $s,
'v' => $v);
575 $h = $input[
'h'] % 360;
576 $s = max(0,min(1,$input[
's']));
577 $v = max(0,min(1,$input[
'v']));
579 return Array(
'r' => $v,
'g' => $v,
'b' => $v);
591 $q = $v * (1 - $s * $f );
593 $t = $v * (1 - $s * (1 - $f ));
626 return Array(
'r' => $r,
'g' => $g,
'b' => $b);
672 $weight_r = $c[
'r'] * 0.75;
673 $weight_g = $c[
'g'] * 1.75;
674 $weight_b = $c[
'b'] * 0.5;
675 if (($weight_r + $weight_g + $weight_b) >= 1.5) {
695 $c[
'r'] += ((1 - $c[
'r']) / 2);
696 $c[
'g'] += ((1 - $c[
'g']) / 2);
697 $c[
'b'] += ((1 - $c[
'b']) / 2);
735 if ($amount > 0 && $amount <= 1) {
736 $c[
'r'] += ((1 - $c[
'r']) * $amount);
737 $c[
'g'] += ((1 - $c[
'g']) * $amount);
738 $c[
'b'] += ((1 - $c[
'b']) * $amount);
739 } elseif ($amount < 0 && $amount >= -1) {
740 $c[
'r'] += ($c[
'r'] * $amount);
741 $c[
'g'] += ($c[
'g'] * $amount);
742 $c[
'b'] += ($c[
'b'] * $amount);
762 $avg = ($c[
'r'] + $c[
'g'] + $c[
'b']) / 3.0;
764 if ($amount < -1) $amount = -1;
765 $c[
'r'] = ($avg * -$amount) + ($c[
'r'] * (1 + $amount));
766 $c[
'g'] = ($avg * -$amount) + ($c[
'g'] * (1 + $amount));
767 $c[
'b'] = ($avg * -$amount) + ($c[
'b'] * (1 + $amount));
768 } elseif ($amount > 0) {
769 if ($amount > 1) $amount = 1;
770 $c[
'r'] = ( (($c[
'r'] > $avg) ? 1 : 0) * $amount) + ($c[
'r'] * (1 - $amount));
771 $c[
'g'] = ( (($c[
'g'] > $avg) ? 1 : 0) * $amount) + ($c[
'g'] * (1 - $amount));
772 $c[
'b'] = ( (($c[
'b'] > $avg) ? 1 : 0) * $amount) + ($c[
'b'] * (1 - $amount));
789 public static function mix($a, $b, $ratio=0.5)
791 $ratio = max(0,min(1,$ratio));
795 'r' => $a[
'r'] * (1-$ratio) + $b[
'r'] * $ratio,
796 'g' => $a[
'g'] * (1-$ratio) + $b[
'g'] * $ratio,
797 'b' => $a[
'b'] * (1-$ratio) + $b[
'b'] * $ratio,
869 if ($h < 0) $h = 360.0 + $h;
871 while ($hsv[
'h'] > 360.0) $hsv[
'h'] -= 360.0;
874 if ($s > 0) $hsv[
's'] += $s * (1 - $hsv[
's']);
875 else $hsv[
's'] += $s * $hsv[
's'];
878 if ($v > 0) $hsv[
'v'] += $v * (1 - $hsv[
'v']);
879 else $hsv[
'v'] += $v * $hsv[
'v'];
900 $r[
'h'] = $b[
'h'] - $a[
'h'];
901 if (abs($r[
'h']) > 180.0) {
902 if ($r[
'h'] > 0) $r[
'h'] -= 360.0;
903 else $r[
'h'] += 360.0;
905 if ($b[
's'] > $a[
's']) $r[
's'] = $b[
's'] / (1 - $a[
's']) - $a[
's'];
906 else $r[
's'] = ($b[
's'] - $a[
's']) / $a[
's'];
907 if ($b[
'v'] > $a[
'v']) $r[
'v'] = $b[
'v'] / (1 - $a[
'v']) - $a[
'v'];
908 else $r[
'v'] = ($b[
'v'] - $a[
'v']) / $a[
'v'];
927 public static function remap($input_html,$map,$tolerance=0.2)
929 $tolerance = min(max($tolerance,0),1);
933 $closeness_total = Array();
934 foreach ($map as $from => $to) {
936 if ($from == $input_html) {
943 $map_diff = Array(
'h'=>$to[
'h']-$from[
'h'],
's'=>$to[
's']-$from[
's'],
'v'=>$to[
'v']-$from[
'v']);
945 $in_diff = Array(
'h'=>$input_hsv[
'h']-$from[
'h'],
's'=>$input_hsv[
's']-$from[
's'],
'v'=>$input_hsv[
'v']-$from[
'v']);
949 $closeness[
'h'] = pow(1 - abs($in_diff[
'h'])/360, 16);
950 $closeness[
's'] = pow(1 - abs($in_diff[
's']), 8);
951 $closeness[
'v'] = pow(1 - abs($in_diff[
'v']), 2);
953 $tolerance = min(max($tolerance,0),1);
955 $closeness[
'h'] *= $tolerance;
956 $closeness[
's'] *= $tolerance;
957 $closeness[
'v'] *= $tolerance;
959 $closeness[
'h'] = max(0,$closeness[
'h']);
960 $closeness[
's'] = max(0,$closeness[
's']);
961 $closeness[
'v'] = max(0,$closeness[
'v']);
964 $closeness[
's'] *= pow($closeness[
'h'],1);
965 $closeness[
'v'] *= pow($closeness[
'h'],1);
968 $closeness_total[
'h'] += $closeness[
'h'];
969 $closeness_total[
's'] += $closeness[
's'];
970 $closeness_total[
'v'] += $closeness[
'v'];
975 $shift[
'h'] += $map_diff[
'h'] * $closeness[
'h'];
976 $shift[
's'] += $map_diff[
's'] * $closeness[
's'];
977 $shift[
'v'] += $map_diff[
'v'] * $closeness[
'v'];
985 $input_hsv[
'h'] += $shift[
'h'] / $closeness_total[
'h'];
986 $input_hsv[
's'] += $shift[
's'] / $closeness_total[
's'];
987 $input_hsv[
'v'] += $shift[
'v'] / $closeness_total[
'v'];