1<?php
2/**
3 * Simple class to query CSS color values and names.
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     LarsDW223
7 */
8
9/**
10 * Class csscolors
11 */
12class csscolors {
13    protected static $values = array(
14                            'aliceblue'            => '#F0F8FF',
15                            'antiquewhite'         => '#FAEBD7',
16                            'aqua'                 => '#00FFFF',
17                            'aquamarine'           => '#7FFFD4',
18                            'azure'                => '#F0FFFF',
19                            'beige'                => '#F5F5DC',
20                            'bisque'               => '#FFE4C4',
21                            'black'                => '#000000',
22                            'blanchedalmond'       => '#FFEBCD',
23                            'blue'                 => '#0000FF',
24                            'blueviolet'           => '#8A2BE2',
25                            'brown'                => '#A52A2A',
26                            'burlywood'            => '#DEB887',
27                            'cadetblue'            => '#5F9EA0',
28                            'chartreuse'           => '#7FFF00',
29                            'chocolate'            => '#D2691E',
30                            'coral'                => '#FF7F50',
31                            'cornflowerblue'       => '#6495ED',
32                            'cornsilk'             => '#FFF8DC',
33                            'crimson'              => '#DC143C',
34                            'cyan'                 => '#00FFFF',
35                            'darkblue'             => '#00008B',
36                            'darkcyan'             => '#008B8B',
37                            'darkgoldenrod'        => '#B8860B',
38                            'darkgray'             => '#A9A9A9',
39                            'darkgreen'            => '#006400',
40                            'darkkhaki'            => '#BDB76B',
41                            'darkmagenta'          => '#8B008B',
42                            'darkolivegreen'       => '#556B2F',
43                            'darkorange'           => '#FF8C00',
44                            'darkorchid'           => '#9932CC',
45                            'darkred'              => '#8B0000',
46                            'darksalmon'           => '#E9967A',
47                            'darkseagreen'         => '#8FBC8F',
48                            'darkslateblue'        => '#483D8B',
49                            'darkslategray'        => '#2F4F4F',
50                            'darkturquoise'        => '#00CED1',
51                            'darkviolet'           => '#9400D3',
52                            'deeppink'             => '#FF1493',
53                            'deepskyblue'          => '#00BFFF',
54                            'dimgray'              => '#696969',
55                            'dodgerblue'           => '#1E90FF',
56                            'firebrick'            => '#B22222',
57                            'floralwhite'          => '#FFFAF0',
58                            'forestgreen'          => '#228B22',
59                            'fuchsia'              => '#FF00FF',
60                            'gainsboro'            => '#DCDCDC',
61                            'ghostwhite'           => '#F8F8FF',
62                            'gold'                 => '#FFD700',
63                            'goldenrod'            => '#DAA520',
64                            'gray'                 => '#808080',
65                            'green'                => '#008000',
66                            'greenyellow'          => '#ADFF2F',
67                            'honeydew'             => '#F0FFF0',
68                            'hotpink'              => '#FF69B4',
69                            'indianred'            => '#CD5C5C',
70                            'indigo'               => '#4B0082',
71                            'ivory'                => '#FFFFF0',
72                            'khaki'                => '#F0E68C',
73                            'lavender'             => '#E6E6FA',
74                            'lavenderblush'        => '#FFF0F5',
75                            'lawngreen'            => '#7CFC00',
76                            'lemonchiffon'         => '#FFFACD',
77                            'lightblue'            => '#ADD8E6',
78                            'lightcoral'           => '#F08080',
79                            'lightcyan'            => '#E0FFFF',
80                            'lightgoldenrodyellow' => '#E0FFFF',
81                            'lightgray'            => '#D3D3D3',
82                            'lightgreen'           => '#90EE90',
83                            'lightpink'            => '#FFB6C1',
84                            'lightsalmon'          => '#FFA07A',
85                            'lightseagreen'        => '#20B2AA',
86                            'lightskyblue'         => '#87CEFA',
87                            'lightslategray'       => '#778899',
88                            'lightsteelblue'       => '#B0C4DE',
89                            'lightyellow'          => '#FFFFE0',
90                            'lime'                 => '#00FF00',
91                            'limegreen'            => '#32CD32',
92                            'linen'                => '#FAF0E6',
93                            'magenta'              => '#FF00FF',
94                            'maroon'               => '#800000',
95                            'mediumaquamarine'     => '#66CDAA',
96                            'mediumblue'           => '#0000CD',
97                            'mediumorchid'         => '#BA55D3',
98                            'mediumpurple'         => '#9370DB',
99                            'mediumseagreen'       => '#3CB371',
100                            'mediumslateblue'      => '#7B68EE',
101                            'mediumspringgreen'    => '#00FA9A',
102                            'mediumturquoise'      => '#48D1CC',
103                            'mediumvioletred'      => '#C71585',
104                            'midnightblue'         => '#191970',
105                            'mintcream'            => '#F5FFFA',
106                            'mistyrose'            => '#FFE4E1',
107                            'moccasin'             => '#FFE4B5',
108                            'navajowhite'          => '#FFDEAD',
109                            'navy'                 => '#000080',
110                            'oldlace'              => '#FDF5E6',
111                            'olive'                => '#808000',
112                            'olivedrab'            => '#6B8E23',
113                            'orange'               => '#FFA500',
114                            'orangered'            => '#FF4500',
115                            'orchid'               => '#DA70D6',
116                            'palegoldenrod'        => '#EEE8AA',
117                            'palegreen'            => '#98FB98',
118                            'paleturquoise'        => '#AFEEEE',
119                            'palevioletred'        => '#DB7093',
120                            'papayawhip'           => '#FFEFD5',
121                            'peachpuff'            => '#FFDAB9',
122                            'peru'                 => '#CD853F',
123                            'pink'                 => '#FFC0CB',
124                            'plum'                 => '#DDA0DD',
125                            'powderblue'           => '#B0E0E6',
126                            'purple'               => '#800080',
127                            'red'                  => '#FF0000',
128                            'rosybrown'            => '#BC8F8F',
129                            'royalblue'            => '#4169E1',
130                            'saddlebrown'          => '#8B4513',
131                            'salmon'               => '#FA8072',
132                            'sandybrown'           => '#F4A460',
133                            'seagreen'             => '#2E8B57',
134                            'seashell'             => '#FFF5EE',
135                            'sienna'               => '#A0522D',
136                            'silver'               => '#C0C0C0',
137                            'skyblue'              => '#87CEEB',
138                            'slateblue'            => '#6A5ACD',
139                            'slategray'            => '#708090',
140                            'snow'                 => '#FFFAFA',
141                            'springgreen'          => '#00FF7F',
142                            'steelblue'            => '#4682B4',
143                            'tan'                  => '#D2B48C',
144                            'teal'                 => '#008080',
145                            'thistle'              => '#D8BFD8',
146                            'tomato'               => '#FF6347',
147                            'turquoise'            => '#40E0D0',
148                            'violet'               => '#EE82EE',
149                            'wheat'                => '#F5DEB3',
150                            'white'                => '#FFFFFF',
151                            'whitesmoke'           => '#F5F5F5',
152                            'yellow'               => '#FFFF00',
153                            'yellowgreen'          => '#9ACD32',
154                        );
155    protected static $names = array(
156                            '#F0F8FF' => 'AliceBlue',
157                            '#FAEBD7' => 'AntiqueWhite',
158                            // '#00FFFF' => 'Aqua',  //duplicated key with Cyan
159                            '#7FFFD4' => 'Aquamarine',
160                            '#F0FFFF' => 'Azure',
161                            '#F5F5DC' => 'Beige',
162                            '#FFE4C4' => 'Bisque',
163                            '#000000' => 'Black',
164                            '#FFEBCD' => 'BlanchedAlmond',
165                            '#0000FF' => 'Blue',
166                            '#8A2BE2' => 'BlueViolet',
167                            '#A52A2A' => 'Brown',
168                            '#DEB887' => 'BurlyWood',
169                            '#5F9EA0' => 'CadetBlue',
170                            '#7FFF00' => 'Chartreuse',
171                            '#D2691E' => 'Chocolate',
172                            '#FF7F50' => 'Coral',
173                            '#6495ED' => 'CornflowerBlue',
174                            '#FFF8DC' => 'Cornsilk',
175                            '#DC143C' => 'Crimson',
176                            '#00FFFF' => 'Cyan',
177                            '#00008B' => 'DarkBlue',
178                            '#008B8B' => 'DarkCyan',
179                            '#B8860B' => 'DarkGoldenRod',
180                            '#A9A9A9' => 'DarkGray',
181                            '#006400' => 'DarkGreen',
182                            '#BDB76B' => 'DarkKhaki',
183                            '#8B008B' => 'DarkMagenta',
184                            '#556B2F' => 'DarkOliveGreen',
185                            '#FF8C00' => 'DarkOrange',
186                            '#9932CC' => 'DarkOrchid',
187                            '#8B0000' => 'DarkRed',
188                            '#E9967A' => 'DarkSalmon',
189                            '#8FBC8F' => 'DarkSeaGreen',
190                            '#483D8B' => 'DarkSlateBlue',
191                            '#2F4F4F' => 'DarkSlateGray',
192                            '#00CED1' => 'DarkTurquoise',
193                            '#9400D3' => 'DarkViolet',
194                            '#FF1493' => 'DeepPink',
195                            '#00BFFF' => 'DeepSkyBlue',
196                            '#696969' => 'DimGray',
197                            '#1E90FF' => 'DodgerBlue',
198                            '#B22222' => 'FireBrick',
199                            '#FFFAF0' => 'FloralWhite',
200                            '#228B22' => 'ForestGreen',
201                            //'#FF00FF' => 'Fuchsia',  //duplicated key with Magenta
202                            '#DCDCDC' => 'Gainsboro',
203                            '#F8F8FF' => 'GhostWhite',
204                            '#FFD700' => 'Gold',
205                            '#DAA520' => 'GoldenRod',
206                            '#808080' => 'Gray',
207                            '#008000' => 'Green',
208                            '#ADFF2F' => 'GreenYellow',
209                            '#F0FFF0' => 'HoneyDew',
210                            '#FF69B4' => 'HotPink',
211                            '#CD5C5C' => 'IndianRed',
212                            '#4B0082' => 'Indigo',
213                            '#FFFFF0' => 'Ivory',
214                            '#F0E68C' => 'Khaki',
215                            '#E6E6FA' => 'Lavender',
216                            '#FFF0F5' => 'LavenderBlush',
217                            '#7CFC00' => 'LawnGreen',
218                            '#FFFACD' => 'LemonChiffon',
219                            '#ADD8E6' => 'LightBlue',
220                            '#F08080' => 'LightCoral',
221                            '#E0FFFF' => 'LightCyan',
222                            //'#E0FFFF' => 'LightGoldenRodYellow', //duplicated key with LightCyan
223                            '#D3D3D3' => 'LightGray',
224                            '#90EE90' => 'LightGreen',
225                            '#FFB6C1' => 'LightPink',
226                            '#FFA07A' => 'LightSalmon',
227                            '#20B2AA' => 'LightSeaGreen',
228                            '#87CEFA' => 'LightSkyBlue',
229                            '#778899' => 'LightSlateGray',
230                            '#B0C4DE' => 'LightSteelBlue',
231                            '#FFFFE0' => 'LightYellow',
232                            '#00FF00' => 'Lime',
233                            '#32CD32' => 'LimeGreen',
234                            '#FAF0E6' => 'Linen',
235                            '#FF00FF' => 'Magenta',
236                            '#800000' => 'Maroon',
237                            '#66CDAA' => 'MediumAquaMarine',
238                            '#0000CD' => 'MediumBlue',
239                            '#BA55D3' => 'MediumOrchid',
240                            '#9370DB' => 'MediumPurple',
241                            '#3CB371' => 'MediumSeaGreen',
242                            '#7B68EE' => 'MediumSlateBlue',
243                            '#00FA9A' => 'MediumSpringGreen',
244                            '#48D1CC' => 'MediumTurquoise',
245                            '#C71585' => 'MediumVioletRed',
246                            '#191970' => 'MidnightBlue',
247                            '#F5FFFA' => 'MintCream',
248                            '#FFE4E1' => 'MistyRose',
249                            '#FFE4B5' => 'Moccasin',
250                            '#FFDEAD' => 'NavajoWhite',
251                            '#000080' => 'Navy',
252                            '#FDF5E6' => 'OldLace',
253                            '#808000' => 'Olive',
254                            '#6B8E23' => 'OliveDrab',
255                            '#FFA500' => 'Orange',
256                            '#FF4500' => 'OrangeRed',
257                            '#DA70D6' => 'Orchid',
258                            '#EEE8AA' => 'PaleGoldenRod',
259                            '#98FB98' => 'PaleGreen',
260                            '#AFEEEE' => 'PaleTurquoise',
261                            '#DB7093' => 'PaleVioletRed',
262                            '#FFEFD5' => 'PapayaWhip',
263                            '#FFDAB9' => 'PeachPuff',
264                            '#CD853F' => 'Peru',
265                            '#FFC0CB' => 'Pink',
266                            '#DDA0DD' => 'Plum',
267                            '#B0E0E6' => 'PowderBlue',
268                            '#800080' => 'Purple',
269                            '#FF0000' => 'Red',
270                            '#BC8F8F' => 'RosyBrown',
271                            '#4169E1' => 'RoyalBlue',
272                            '#8B4513' => 'SaddleBrown',
273                            '#FA8072' => 'Salmon',
274                            '#F4A460' => 'SandyBrown',
275                            '#2E8B57' => 'SeaGreen',
276                            '#FFF5EE' => 'SeaShell',
277                            '#A0522D' => 'Sienna',
278                            '#C0C0C0' => 'Silver',
279                            '#87CEEB' => 'SkyBlue',
280                            '#6A5ACD' => 'SlateBlue',
281                            '#708090' => 'SlateGray',
282                            '#FFFAFA' => 'Snow',
283                            '#00FF7F' => 'SpringGreen',
284                            '#4682B4' => 'SteelBlue',
285                            '#D2B48C' => 'Tan',
286                            '#008080' => 'Teal',
287                            '#D8BFD8' => 'Thistle',
288                            '#FF6347' => 'Tomato',
289                            '#40E0D0' => 'Turquoise',
290                            '#EE82EE' => 'Violet',
291                            '#F5DEB3' => 'Wheat',
292                            '#FFFFFF' => 'White',
293                            '#F5F5F5' => 'WhiteSmoke',
294                            '#FFFF00' => 'Yellow',
295                            '#9ACD32' => 'YellowGreen',
296                        );
297
298    /**
299     * @param string|null $name
300     * @return string
301     */
302    public static function getColorValue ($name=NULL) {
303        $value = '#000000';
304        if (isset($name)) {
305            if (isset(self::$values [strtolower($name)])) {
306                $value = self::$values [strtolower($name)];
307            } else {
308                $value = '#000000';
309            }
310        }
311        return $value;
312    }
313
314    /**
315     * @param null $value
316     * @return string
317     */
318    public static function getValueName ($value=NULL) {
319        $name = 'Black';
320        if (isset($value)) {
321            $name = self::$names [$value];
322            if (!isset($name))
323                $name = 'Black';
324        }
325        return $name;
326    }
327
328    /**
329     * @param string $name
330     * @return boolean
331     */
332    public static function isKnownColorName ($name=NULL) {
333        if (isset($name)) {
334            return array_key_exists(strtolower($name), self::$values);
335        }
336        return false;
337    }
338}
339