1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* JPGraph v4.0.3 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Amenadiel\JpGraph\Image; |
8
|
|
|
|
9
|
|
|
use Amenadiel\JpGraph\Util; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* File: JPGRAPH_RGB.INC.PHP |
13
|
|
|
* // Description: Class to handle RGb color space specification and |
14
|
|
|
* // named colors |
15
|
|
|
* // Created: 2001-01-08 (Refactored to separate file 2008-08-01) |
16
|
|
|
* // Ver: $Id: jpgraph_rgb.inc.php 1893 2009-10-02 23:15:25Z ljp $ |
17
|
|
|
* // |
18
|
|
|
* // Copyright (c) Asial Corporation. All rights reserved. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @class RGB |
23
|
|
|
* // Description: Color definitions as RGB triples |
24
|
|
|
*/ |
25
|
|
|
class RGB |
26
|
|
|
{ |
27
|
|
|
public $rgb_table; |
28
|
|
|
public $img; |
29
|
|
|
|
30
|
21 |
|
public function __construct($aImg = null) |
31
|
|
|
{ |
32
|
21 |
|
$this->img = $aImg; |
33
|
|
|
|
34
|
|
|
// Conversion array between color names and RGB |
35
|
21 |
|
$this->rgb_table = [ |
36
|
|
|
'aqua' => [0, 255, 255], |
37
|
|
|
'lime' => [0, 255, 0], |
38
|
|
|
'teal' => [0, 128, 128], |
39
|
|
|
'whitesmoke' => [245, 245, 245], |
40
|
|
|
'gainsboro' => [220, 220, 220], |
41
|
|
|
'oldlace' => [253, 245, 230], |
42
|
|
|
'linen' => [250, 240, 230], |
43
|
|
|
'antiquewhite' => [250, 235, 215], |
44
|
|
|
'papayawhip' => [255, 239, 213], |
45
|
|
|
'blanchedalmond' => [255, 235, 205], |
46
|
|
|
'bisque' => [255, 228, 196], |
47
|
|
|
'peachpuff' => [255, 218, 185], |
48
|
|
|
'navajowhite' => [255, 222, 173], |
49
|
|
|
'moccasin' => [255, 228, 181], |
50
|
|
|
'cornsilk' => [255, 248, 220], |
51
|
|
|
'ivory' => [255, 255, 240], |
52
|
|
|
'lemonchiffon' => [255, 250, 205], |
53
|
|
|
'seashell' => [255, 245, 238], |
54
|
|
|
'mintcream' => [245, 255, 250], |
55
|
|
|
'azure' => [240, 255, 255], |
56
|
|
|
'aliceblue' => [240, 248, 255], |
57
|
|
|
'lavender' => [230, 230, 250], |
58
|
|
|
'lavenderblush' => [255, 240, 245], |
59
|
|
|
'mistyrose' => [255, 228, 225], |
60
|
|
|
'white' => [255, 255, 255], |
61
|
|
|
'black' => [0, 0, 0], |
62
|
|
|
'darkslategray' => [47, 79, 79], |
63
|
|
|
'dimgray' => [105, 105, 105], |
64
|
|
|
'slategray' => [112, 128, 144], |
65
|
|
|
'lightslategray' => [119, 136, 153], |
66
|
|
|
'gray' => [190, 190, 190], |
67
|
|
|
'lightgray' => [211, 211, 211], |
68
|
|
|
'midnightblue' => [25, 25, 112], |
69
|
|
|
'navy' => [0, 0, 128], |
70
|
|
|
'indigo' => [75, 0, 130], |
71
|
|
|
'electricindigo' => [102, 0, 255], |
72
|
|
|
'deepindigo' => [138, 43, 226], |
73
|
|
|
'pigmentindigo' => [75, 0, 130], |
74
|
|
|
'indigodye' => [0, 65, 106], |
75
|
|
|
'cornflowerblue' => [100, 149, 237], |
76
|
|
|
'darkslateblue' => [72, 61, 139], |
77
|
|
|
'slateblue' => [106, 90, 205], |
78
|
|
|
'mediumslateblue' => [123, 104, 238], |
79
|
|
|
'lightslateblue' => [132, 112, 255], |
80
|
|
|
'mediumblue' => [0, 0, 205], |
81
|
|
|
'royalblue' => [65, 105, 225], |
82
|
|
|
'blue' => [0, 0, 255], |
83
|
|
|
'dodgerblue' => [30, 144, 255], |
84
|
|
|
'deepskyblue' => [0, 191, 255], |
85
|
|
|
'skyblue' => [135, 206, 235], |
86
|
|
|
'lightskyblue' => [135, 206, 250], |
87
|
|
|
'steelblue' => [70, 130, 180], |
88
|
|
|
'lightred' => [211, 167, 168], |
89
|
|
|
'lightsteelblue' => [176, 196, 222], |
90
|
|
|
'lightblue' => [173, 216, 230], |
91
|
|
|
'powderblue' => [176, 224, 230], |
92
|
|
|
'paleturquoise' => [175, 238, 238], |
93
|
|
|
'darkturquoise' => [0, 206, 209], |
94
|
|
|
'mediumturquoise' => [72, 209, 204], |
95
|
|
|
'turquoise' => [64, 224, 208], |
96
|
|
|
'cyan' => [0, 255, 255], |
97
|
|
|
'lightcyan' => [224, 255, 255], |
98
|
|
|
'cadetblue' => [95, 158, 160], |
99
|
|
|
'mediumaquamarine' => [102, 205, 170], |
100
|
|
|
'aquamarine' => [127, 255, 212], |
101
|
|
|
'darkgreen' => [0, 100, 0], |
102
|
|
|
'darkolivegreen' => [85, 107, 47], |
103
|
|
|
'darkseagreen' => [143, 188, 143], |
104
|
|
|
'seagreen' => [46, 139, 87], |
105
|
|
|
'mediumseagreen' => [60, 179, 113], |
106
|
|
|
'lightseagreen' => [32, 178, 170], |
107
|
|
|
'palegreen' => [152, 251, 152], |
108
|
|
|
'springgreen' => [0, 255, 127], |
109
|
|
|
'lawngreen' => [124, 252, 0], |
110
|
|
|
'green' => [0, 255, 0], |
111
|
|
|
'chartreuse' => [127, 255, 0], |
112
|
|
|
'mediumspringgreen' => [0, 250, 154], |
113
|
|
|
'greenyellow' => [173, 255, 47], |
114
|
|
|
'limegreen' => [50, 205, 50], |
115
|
|
|
'yellowgreen' => [154, 205, 50], |
116
|
|
|
'forestgreen' => [34, 139, 34], |
117
|
|
|
'olivedrab' => [107, 142, 35], |
118
|
|
|
'darkkhaki' => [189, 183, 107], |
119
|
|
|
'khaki' => [240, 230, 140], |
120
|
|
|
'palegoldenrod' => [238, 232, 170], |
121
|
|
|
'lightgoldenrodyellow' => [250, 250, 210], |
122
|
|
|
'lightyellow' => [255, 255, 200], |
123
|
|
|
'yellow' => [255, 255, 0], |
124
|
|
|
'gold' => [255, 215, 0], |
125
|
|
|
'lightgoldenrod' => [238, 221, 130], |
126
|
|
|
'goldenrod' => [218, 165, 32], |
127
|
|
|
'darkgoldenrod' => [184, 134, 11], |
128
|
|
|
'rosybrown' => [188, 143, 143], |
129
|
|
|
'indianred' => [205, 92, 92], |
130
|
|
|
'saddlebrown' => [139, 69, 19], |
131
|
|
|
'sienna' => [160, 82, 45], |
132
|
|
|
'peru' => [205, 133, 63], |
133
|
|
|
'burlywood' => [222, 184, 135], |
134
|
|
|
'beige' => [245, 245, 220], |
135
|
|
|
'wheat' => [245, 222, 179], |
136
|
|
|
'sandybrown' => [244, 164, 96], |
137
|
|
|
'tan' => [210, 180, 140], |
138
|
|
|
'chocolate' => [210, 105, 30], |
139
|
|
|
'firebrick' => [178, 34, 34], |
140
|
|
|
'brown' => [165, 42, 42], |
141
|
|
|
'darksalmon' => [233, 150, 122], |
142
|
|
|
'salmon' => [250, 128, 114], |
143
|
|
|
'lightsalmon' => [255, 160, 122], |
144
|
|
|
'orange' => [255, 165, 0], |
145
|
|
|
'darkorange' => [255, 140, 0], |
146
|
|
|
'coral' => [255, 127, 80], |
147
|
|
|
'lightcoral' => [240, 128, 128], |
148
|
|
|
'tomato' => [255, 99, 71], |
149
|
|
|
'orangered' => [255, 69, 0], |
150
|
|
|
'red' => [255, 0, 0], |
151
|
|
|
'hotpink' => [255, 105, 180], |
152
|
|
|
'deeppink' => [255, 20, 147], |
153
|
|
|
'pink' => [255, 192, 203], |
154
|
|
|
'lightpink' => [255, 182, 193], |
155
|
|
|
'palevioletred' => [219, 112, 147], |
156
|
|
|
'maroon' => [176, 48, 96], |
157
|
|
|
'mediumvioletred' => [199, 21, 133], |
158
|
|
|
'violetred' => [208, 32, 144], |
159
|
|
|
'magenta' => [255, 0, 255], |
160
|
|
|
'violet' => [238, 130, 238], |
161
|
|
|
'plum' => [221, 160, 221], |
162
|
|
|
'orchid' => [218, 112, 214], |
163
|
|
|
'mediumorchid' => [186, 85, 211], |
164
|
|
|
'darkorchid' => [153, 50, 204], |
165
|
|
|
'darkviolet' => [148, 0, 211], |
166
|
|
|
'blueviolet' => [138, 43, 226], |
167
|
|
|
'purple' => [160, 32, 240], |
168
|
|
|
'mediumpurple' => [147, 112, 219], |
169
|
|
|
'thistle' => [216, 191, 216], |
170
|
|
|
'snow1' => [255, 250, 250], |
171
|
|
|
'snow2' => [238, 233, 233], |
172
|
|
|
'snow3' => [205, 201, 201], |
173
|
|
|
'snow4' => [139, 137, 137], |
174
|
|
|
'seashell1' => [255, 245, 238], |
175
|
|
|
'seashell2' => [238, 229, 222], |
176
|
|
|
'seashell3' => [205, 197, 191], |
177
|
|
|
'seashell4' => [139, 134, 130], |
178
|
|
|
'AntiqueWhite1' => [255, 239, 219], |
179
|
|
|
'AntiqueWhite2' => [238, 223, 204], |
180
|
|
|
'AntiqueWhite3' => [205, 192, 176], |
181
|
|
|
'AntiqueWhite4' => [139, 131, 120], |
182
|
|
|
'bisque1' => [255, 228, 196], |
183
|
|
|
'bisque2' => [238, 213, 183], |
184
|
|
|
'bisque3' => [205, 183, 158], |
185
|
|
|
'bisque4' => [139, 125, 107], |
186
|
|
|
'peachPuff1' => [255, 218, 185], |
187
|
|
|
'peachpuff2' => [238, 203, 173], |
188
|
|
|
'peachpuff3' => [205, 175, 149], |
189
|
|
|
'peachpuff4' => [139, 119, 101], |
190
|
|
|
'navajowhite1' => [255, 222, 173], |
191
|
|
|
'navajowhite2' => [238, 207, 161], |
192
|
|
|
'navajowhite3' => [205, 179, 139], |
193
|
|
|
'navajowhite4' => [139, 121, 94], |
194
|
|
|
'lemonchiffon1' => [255, 250, 205], |
195
|
|
|
'lemonchiffon2' => [238, 233, 191], |
196
|
|
|
'lemonchiffon3' => [205, 201, 165], |
197
|
|
|
'lemonchiffon4' => [139, 137, 112], |
198
|
|
|
'ivory1' => [255, 255, 240], |
199
|
|
|
'ivory2' => [238, 238, 224], |
200
|
|
|
'ivory3' => [205, 205, 193], |
201
|
|
|
'ivory4' => [139, 139, 131], |
202
|
|
|
'honeydew' => [193, 205, 193], |
203
|
|
|
'lavenderblush1' => [255, 240, 245], |
204
|
|
|
'lavenderblush2' => [238, 224, 229], |
205
|
|
|
'lavenderblush3' => [205, 193, 197], |
206
|
|
|
'lavenderblush4' => [139, 131, 134], |
207
|
|
|
'mistyrose1' => [255, 228, 225], |
208
|
|
|
'mistyrose2' => [238, 213, 210], |
209
|
|
|
'mistyrose3' => [205, 183, 181], |
210
|
|
|
'mistyrose4' => [139, 125, 123], |
211
|
|
|
'azure1' => [240, 255, 255], |
212
|
|
|
'azure2' => [224, 238, 238], |
213
|
|
|
'azure3' => [193, 205, 205], |
214
|
|
|
'azure4' => [131, 139, 139], |
215
|
|
|
'slateblue1' => [131, 111, 255], |
216
|
|
|
'slateblue2' => [122, 103, 238], |
217
|
|
|
'slateblue3' => [105, 89, 205], |
218
|
|
|
'slateblue4' => [71, 60, 139], |
219
|
|
|
'royalblue1' => [72, 118, 255], |
220
|
|
|
'royalblue2' => [67, 110, 238], |
221
|
|
|
'royalblue3' => [58, 95, 205], |
222
|
|
|
'royalblue4' => [39, 64, 139], |
223
|
|
|
'dodgerblue1' => [30, 144, 255], |
224
|
|
|
'dodgerblue2' => [28, 134, 238], |
225
|
|
|
'dodgerblue3' => [24, 116, 205], |
226
|
|
|
'dodgerblue4' => [16, 78, 139], |
227
|
|
|
'steelblue1' => [99, 184, 255], |
228
|
|
|
'steelblue2' => [92, 172, 238], |
229
|
|
|
'steelblue3' => [79, 148, 205], |
230
|
|
|
'steelblue4' => [54, 100, 139], |
231
|
|
|
'deepskyblue1' => [0, 191, 255], |
232
|
|
|
'deepskyblue2' => [0, 178, 238], |
233
|
|
|
'deepskyblue3' => [0, 154, 205], |
234
|
|
|
'deepskyblue4' => [0, 104, 139], |
235
|
|
|
'skyblue1' => [135, 206, 255], |
236
|
|
|
'skyblue2' => [126, 192, 238], |
237
|
|
|
'skyblue3' => [108, 166, 205], |
238
|
|
|
'skyblue4' => [74, 112, 139], |
239
|
|
|
'lightskyblue1' => [176, 226, 255], |
240
|
|
|
'lightskyblue2' => [164, 211, 238], |
241
|
|
|
'lightskyblue3' => [141, 182, 205], |
242
|
|
|
'lightskyblue4' => [96, 123, 139], |
243
|
|
|
'slategray1' => [198, 226, 255], |
244
|
|
|
'slategray2' => [185, 211, 238], |
245
|
|
|
'slategray3' => [159, 182, 205], |
246
|
|
|
'slategray4' => [108, 123, 139], |
247
|
|
|
'lightsteelblue1' => [202, 225, 255], |
248
|
|
|
'lightsteelblue2' => [188, 210, 238], |
249
|
|
|
'lightsteelblue3' => [162, 181, 205], |
250
|
|
|
'lightsteelblue4' => [110, 123, 139], |
251
|
|
|
'lightblue1' => [191, 239, 255], |
252
|
|
|
'lightblue2' => [178, 223, 238], |
253
|
|
|
'lightblue3' => [154, 192, 205], |
254
|
|
|
'lightblue4' => [104, 131, 139], |
255
|
|
|
'lightcyan1' => [224, 255, 255], |
256
|
|
|
'lightcyan2' => [209, 238, 238], |
257
|
|
|
'lightcyan3' => [180, 205, 205], |
258
|
|
|
'lightcyan4' => [122, 139, 139], |
259
|
|
|
'paleturquoise1' => [187, 255, 255], |
260
|
|
|
'paleturquoise2' => [174, 238, 238], |
261
|
|
|
'paleturquoise3' => [150, 205, 205], |
262
|
|
|
'paleturquoise4' => [102, 139, 139], |
263
|
|
|
'cadetblue1' => [152, 245, 255], |
264
|
|
|
'cadetblue2' => [142, 229, 238], |
265
|
|
|
'cadetblue3' => [122, 197, 205], |
266
|
|
|
'cadetblue4' => [83, 134, 139], |
267
|
|
|
'turquoise1' => [0, 245, 255], |
268
|
|
|
'turquoise2' => [0, 229, 238], |
269
|
|
|
'turquoise3' => [0, 197, 205], |
270
|
|
|
'turquoise4' => [0, 134, 139], |
271
|
|
|
'cyan1' => [0, 255, 255], |
272
|
|
|
'cyan2' => [0, 238, 238], |
273
|
|
|
'cyan3' => [0, 205, 205], |
274
|
|
|
'cyan4' => [0, 139, 139], |
275
|
|
|
'darkslategray1' => [151, 255, 255], |
276
|
|
|
'darkslategray2' => [141, 238, 238], |
277
|
|
|
'darkslategray3' => [121, 205, 205], |
278
|
|
|
'darkslategray4' => [82, 139, 139], |
279
|
|
|
'aquamarine1' => [127, 255, 212], |
280
|
|
|
'aquamarine2' => [118, 238, 198], |
281
|
|
|
'aquamarine3' => [102, 205, 170], |
282
|
|
|
'aquamarine4' => [69, 139, 116], |
283
|
|
|
'darkseagreen1' => [193, 255, 193], |
284
|
|
|
'darkseagreen2' => [180, 238, 180], |
285
|
|
|
'darkseagreen3' => [155, 205, 155], |
286
|
|
|
'darkseagreen4' => [105, 139, 105], |
287
|
|
|
'seagreen1' => [84, 255, 159], |
288
|
|
|
'seagreen2' => [78, 238, 148], |
289
|
|
|
'seagreen3' => [67, 205, 128], |
290
|
|
|
'seagreen4' => [46, 139, 87], |
291
|
|
|
'palegreen1' => [154, 255, 154], |
292
|
|
|
'palegreen2' => [144, 238, 144], |
293
|
|
|
'palegreen3' => [124, 205, 124], |
294
|
|
|
'palegreen4' => [84, 139, 84], |
295
|
|
|
'springgreen1' => [0, 255, 127], |
296
|
|
|
'springgreen2' => [0, 238, 118], |
297
|
|
|
'springgreen3' => [0, 205, 102], |
298
|
|
|
'springgreen4' => [0, 139, 69], |
299
|
|
|
'chartreuse1' => [127, 255, 0], |
300
|
|
|
'chartreuse2' => [118, 238, 0], |
301
|
|
|
'chartreuse3' => [102, 205, 0], |
302
|
|
|
'chartreuse4' => [69, 139, 0], |
303
|
|
|
'olivedrab1' => [192, 255, 62], |
304
|
|
|
'olivedrab2' => [179, 238, 58], |
305
|
|
|
'olivedrab3' => [154, 205, 50], |
306
|
|
|
'olivedrab4' => [105, 139, 34], |
307
|
|
|
'darkolivegreen1' => [202, 255, 112], |
308
|
|
|
'darkolivegreen2' => [188, 238, 104], |
309
|
|
|
'darkolivegreen3' => [162, 205, 90], |
310
|
|
|
'darkolivegreen4' => [110, 139, 61], |
311
|
|
|
'khaki1' => [255, 246, 143], |
312
|
|
|
'khaki2' => [238, 230, 133], |
313
|
|
|
'khaki3' => [205, 198, 115], |
314
|
|
|
'khaki4' => [139, 134, 78], |
315
|
|
|
'lightgoldenrod1' => [255, 236, 139], |
316
|
|
|
'lightgoldenrod2' => [238, 220, 130], |
317
|
|
|
'lightgoldenrod3' => [205, 190, 112], |
318
|
|
|
'lightgoldenrod4' => [139, 129, 76], |
319
|
|
|
'yellow1' => [255, 255, 0], |
320
|
|
|
'yellow2' => [238, 238, 0], |
321
|
|
|
'yellow3' => [205, 205, 0], |
322
|
|
|
'yellow4' => [139, 139, 0], |
323
|
|
|
'gold1' => [255, 215, 0], |
324
|
|
|
'gold2' => [238, 201, 0], |
325
|
|
|
'gold3' => [205, 173, 0], |
326
|
|
|
'gold4' => [139, 117, 0], |
327
|
|
|
'goldenrod1' => [255, 193, 37], |
328
|
|
|
'goldenrod2' => [238, 180, 34], |
329
|
|
|
'goldenrod3' => [205, 155, 29], |
330
|
|
|
'goldenrod4' => [139, 105, 20], |
331
|
|
|
'darkgoldenrod1' => [255, 185, 15], |
332
|
|
|
'darkgoldenrod2' => [238, 173, 14], |
333
|
|
|
'darkgoldenrod3' => [205, 149, 12], |
334
|
|
|
'darkgoldenrod4' => [139, 101, 8], |
335
|
|
|
'rosybrown1' => [255, 193, 193], |
336
|
|
|
'rosybrown2' => [238, 180, 180], |
337
|
|
|
'rosybrown3' => [205, 155, 155], |
338
|
|
|
'rosybrown4' => [139, 105, 105], |
339
|
|
|
'indianred1' => [255, 106, 106], |
340
|
|
|
'indianred2' => [238, 99, 99], |
341
|
|
|
'indianred3' => [205, 85, 85], |
342
|
|
|
'indianred4' => [139, 58, 58], |
343
|
|
|
'sienna1' => [255, 130, 71], |
344
|
|
|
'sienna2' => [238, 121, 66], |
345
|
|
|
'sienna3' => [205, 104, 57], |
346
|
|
|
'sienna4' => [139, 71, 38], |
347
|
|
|
'burlywood1' => [255, 211, 155], |
348
|
|
|
'burlywood2' => [238, 197, 145], |
349
|
|
|
'burlywood3' => [205, 170, 125], |
350
|
|
|
'burlywood4' => [139, 115, 85], |
351
|
|
|
'wheat1' => [255, 231, 186], |
352
|
|
|
'wheat2' => [238, 216, 174], |
353
|
|
|
'wheat3' => [205, 186, 150], |
354
|
|
|
'wheat4' => [139, 126, 102], |
355
|
|
|
'tan1' => [255, 165, 79], |
356
|
|
|
'tan2' => [238, 154, 73], |
357
|
|
|
'tan3' => [205, 133, 63], |
358
|
|
|
'tan4' => [139, 90, 43], |
359
|
|
|
'chocolate1' => [255, 127, 36], |
360
|
|
|
'chocolate2' => [238, 118, 33], |
361
|
|
|
'chocolate3' => [205, 102, 29], |
362
|
|
|
'chocolate4' => [139, 69, 19], |
363
|
|
|
'firebrick1' => [255, 48, 48], |
364
|
|
|
'firebrick2' => [238, 44, 44], |
365
|
|
|
'firebrick3' => [205, 38, 38], |
366
|
|
|
'firebrick4' => [139, 26, 26], |
367
|
|
|
'brown1' => [255, 64, 64], |
368
|
|
|
'brown2' => [238, 59, 59], |
369
|
|
|
'brown3' => [205, 51, 51], |
370
|
|
|
'brown4' => [139, 35, 35], |
371
|
|
|
'salmon1' => [255, 140, 105], |
372
|
|
|
'salmon2' => [238, 130, 98], |
373
|
|
|
'salmon3' => [205, 112, 84], |
374
|
|
|
'salmon4' => [139, 76, 57], |
375
|
|
|
'lightsalmon1' => [255, 160, 122], |
376
|
|
|
'lightsalmon2' => [238, 149, 114], |
377
|
|
|
'lightsalmon3' => [205, 129, 98], |
378
|
|
|
'lightsalmon4' => [139, 87, 66], |
379
|
|
|
'orange1' => [255, 165, 0], |
380
|
|
|
'orange2' => [238, 154, 0], |
381
|
|
|
'orange3' => [205, 133, 0], |
382
|
|
|
'orange4' => [139, 90, 0], |
383
|
|
|
'darkorange1' => [255, 127, 0], |
384
|
|
|
'darkorange2' => [238, 118, 0], |
385
|
|
|
'darkorange3' => [205, 102, 0], |
386
|
|
|
'darkorange4' => [139, 69, 0], |
387
|
|
|
'coral1' => [255, 114, 86], |
388
|
|
|
'coral2' => [238, 106, 80], |
389
|
|
|
'coral3' => [205, 91, 69], |
390
|
|
|
'coral4' => [139, 62, 47], |
391
|
|
|
'tomato1' => [255, 99, 71], |
392
|
|
|
'tomato2' => [238, 92, 66], |
393
|
|
|
'tomato3' => [205, 79, 57], |
394
|
|
|
'tomato4' => [139, 54, 38], |
395
|
|
|
'orangered1' => [255, 69, 0], |
396
|
|
|
'orangered2' => [238, 64, 0], |
397
|
|
|
'orangered3' => [205, 55, 0], |
398
|
|
|
'orangered4' => [139, 37, 0], |
399
|
|
|
'deeppink1' => [255, 20, 147], |
400
|
|
|
'deeppink2' => [238, 18, 137], |
401
|
|
|
'deeppink3' => [205, 16, 118], |
402
|
|
|
'deeppink4' => [139, 10, 80], |
403
|
|
|
'hotpink1' => [255, 110, 180], |
404
|
|
|
'hotpink2' => [238, 106, 167], |
405
|
|
|
'hotpink3' => [205, 96, 144], |
406
|
|
|
'hotpink4' => [139, 58, 98], |
407
|
|
|
'pink1' => [255, 181, 197], |
408
|
|
|
'pink2' => [238, 169, 184], |
409
|
|
|
'pink3' => [205, 145, 158], |
410
|
|
|
'pink4' => [139, 99, 108], |
411
|
|
|
'lightpink1' => [255, 174, 185], |
412
|
|
|
'lightpink2' => [238, 162, 173], |
413
|
|
|
'lightpink3' => [205, 140, 149], |
414
|
|
|
'lightpink4' => [139, 95, 101], |
415
|
|
|
'palevioletred1' => [255, 130, 171], |
416
|
|
|
'palevioletred2' => [238, 121, 159], |
417
|
|
|
'palevioletred3' => [205, 104, 137], |
418
|
|
|
'palevioletred4' => [139, 71, 93], |
419
|
|
|
'maroon1' => [255, 52, 179], |
420
|
|
|
'maroon2' => [238, 48, 167], |
421
|
|
|
'maroon3' => [205, 41, 144], |
422
|
|
|
'maroon4' => [139, 28, 98], |
423
|
|
|
'violetred1' => [255, 62, 150], |
424
|
|
|
'violetred2' => [238, 58, 140], |
425
|
|
|
'violetred3' => [205, 50, 120], |
426
|
|
|
'violetred4' => [139, 34, 82], |
427
|
|
|
'magenta1' => [255, 0, 255], |
428
|
|
|
'magenta2' => [238, 0, 238], |
429
|
|
|
'magenta3' => [205, 0, 205], |
430
|
|
|
'magenta4' => [139, 0, 139], |
431
|
|
|
'mediumred' => [140, 34, 34], |
432
|
|
|
'orchid1' => [255, 131, 250], |
433
|
|
|
'orchid2' => [238, 122, 233], |
434
|
|
|
'orchid3' => [205, 105, 201], |
435
|
|
|
'orchid4' => [139, 71, 137], |
436
|
|
|
'plum1' => [255, 187, 255], |
437
|
|
|
'plum2' => [238, 174, 238], |
438
|
|
|
'plum3' => [205, 150, 205], |
439
|
|
|
'plum4' => [139, 102, 139], |
440
|
|
|
'mediumorchid1' => [224, 102, 255], |
441
|
|
|
'mediumorchid2' => [209, 95, 238], |
442
|
|
|
'mediumorchid3' => [180, 82, 205], |
443
|
|
|
'mediumorchid4' => [122, 55, 139], |
444
|
|
|
'darkorchid1' => [191, 62, 255], |
445
|
|
|
'darkorchid2' => [178, 58, 238], |
446
|
|
|
'darkorchid3' => [154, 50, 205], |
447
|
|
|
'darkorchid4' => [104, 34, 139], |
448
|
|
|
'purple1' => [155, 48, 255], |
449
|
|
|
'purple2' => [145, 44, 238], |
450
|
|
|
'purple3' => [125, 38, 205], |
451
|
|
|
'purple4' => [85, 26, 139], |
452
|
|
|
'mediumpurple1' => [171, 130, 255], |
453
|
|
|
'mediumpurple2' => [159, 121, 238], |
454
|
|
|
'mediumpurple3' => [137, 104, 205], |
455
|
|
|
'mediumpurple4' => [93, 71, 139], |
456
|
|
|
'thistle1' => [255, 225, 255], |
457
|
|
|
'thistle2' => [238, 210, 238], |
458
|
|
|
'thistle3' => [205, 181, 205], |
459
|
|
|
'thistle4' => [139, 123, 139], |
460
|
|
|
'gray1' => [10, 10, 10], |
461
|
|
|
'gray2' => [40, 40, 30], |
462
|
|
|
'gray3' => [70, 70, 70], |
463
|
|
|
'gray4' => [100, 100, 100], |
464
|
|
|
'gray5' => [130, 130, 130], |
465
|
|
|
'gray6' => [160, 160, 160], |
466
|
|
|
'gray7' => [190, 190, 190], |
467
|
|
|
'gray8' => [210, 210, 210], |
468
|
|
|
'gray9' => [240, 240, 240], |
469
|
|
|
'darkgray' => [100, 100, 100], |
470
|
|
|
'darkblue' => [0, 0, 139], |
471
|
|
|
'darkcyan' => [0, 139, 139], |
472
|
|
|
'darkmagenta' => [139, 0, 139], |
473
|
|
|
'darkred' => [139, 0, 0], |
474
|
|
|
'silver' => [192, 192, 192], |
475
|
|
|
'eggplant' => [144, 176, 168], |
476
|
|
|
'lightgreen' => [144, 238, 144], ]; |
477
|
21 |
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* PUBLIC METHODS. |
481
|
|
|
* |
482
|
|
|
* @param mixed $aColor |
483
|
|
|
*/ |
484
|
|
|
|
485
|
|
|
// Colors can be specified as either |
486
|
|
|
// 1. #xxxxxx HTML style |
487
|
|
|
// 2. "colorname" as a named color |
488
|
|
|
// 3. array(r,g,b) RGB triple |
489
|
|
|
// This function translates this to a native RGB format and returns an |
490
|
|
|
// RGB triple. |
491
|
|
|
|
492
|
21 |
|
public function Color($aColor) |
493
|
|
|
{ |
494
|
21 |
|
if (is_string($aColor)) { |
495
|
21 |
|
$matches = []; |
496
|
|
|
// this regex will parse a color string and fill the $matches array as such: |
497
|
|
|
// 0: the full match if any |
498
|
|
|
// 1: a hex string preceded by a hash, can be 3 characters (#fff) or 6 (#ffffff) (4 or 5 also accepted but...) |
499
|
|
|
// 2,3,4: r,g,b values in hex if the first character of the string is # |
500
|
|
|
// 5: all alpha-numeric characters at the beginning of the string if string does not start with # |
501
|
|
|
// 6: alpha value prefixed by @ if supplied |
502
|
|
|
// 7: alpha value with @ stripped |
503
|
|
|
// 8: adjust value prefixed with : if supplied |
504
|
|
|
// 9: adjust value with : stripped |
505
|
21 |
|
$regex = '/(#([0-9a-fA-F]{1,2})([0-9a-fA-F]{1,2})([0-9a-fA-F]{1,2}))?([\w]+)?(@([\d\.,]+))?(:([\d\.,]+))?/'; |
506
|
21 |
|
if (!preg_match($regex, $aColor, $matches)) { |
507
|
|
|
Util\JpGraphError::RaiseL(25078, $aColor); //(" Unknown color: $aColor"); |
508
|
|
|
} |
509
|
21 |
|
if (empty($matches[5])) { |
510
|
|
|
$r = strlen($matches[2]) == 1 ? $matches[2] . $matches[2] : $matches[2]; |
511
|
|
|
$g = strlen($matches[3]) == 1 ? $matches[3] . $matches[3] : $matches[3]; |
512
|
|
|
$b = strlen($matches[4]) == 1 ? $matches[4] . $matches[4] : $matches[4]; |
513
|
|
|
$r = hexdec($r); |
514
|
|
|
$g = hexdec($g); |
515
|
|
|
$b = hexdec($b); |
516
|
|
|
} else { |
517
|
21 |
|
if (!isset($this->rgb_table[$matches[5]])) { |
518
|
|
|
Util\JpGraphError::RaiseL(25078, $aColor); //(" Unknown color: $aColor"); |
519
|
|
|
} |
520
|
21 |
|
$r = $this->rgb_table[$matches[5]][0]; |
521
|
21 |
|
$g = $this->rgb_table[$matches[5]][1]; |
522
|
21 |
|
$b = $this->rgb_table[$matches[5]][2]; |
523
|
|
|
} |
524
|
21 |
|
$alpha = isset($matches[7]) ? str_replace(',', '.', $matches[7]) : 0; |
525
|
21 |
|
$adj = isset($matches[9]) ? str_replace(',', '.', $matches[9]) : 1.0; |
526
|
|
|
|
527
|
21 |
|
if ($alpha === '') { |
528
|
|
|
$alpha = 0; |
529
|
|
|
} |
530
|
|
|
|
531
|
21 |
|
if ($adj < 0) { |
532
|
|
|
Util\JpGraphError::RaiseL(25077); //('Adjustment factor for color must be > 0'); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
// Scale adj so that an adj=2 always |
536
|
|
|
// makes the color 100% white (i.e. 255,255,255. |
537
|
|
|
// and adj=1 neutral and adj=0 black. |
538
|
21 |
|
if ($adj == 1) { |
539
|
21 |
|
return [$r, $g, $b, $alpha]; |
540
|
|
|
} |
541
|
|
|
if ($adj > 1) { |
542
|
|
|
$m = ($adj - 1.0) * (255 - min(255, min($r, min($g, $b)))); |
543
|
|
|
|
544
|
|
|
return [min(255, $r + $m), min(255, $g + $m), min(255, $b + $m), $alpha]; |
545
|
|
|
} |
546
|
|
|
if ($adj < 1) { |
547
|
|
|
$m = ($adj - 1.0) * max(255, max($r, max($g, $b))); |
548
|
|
|
|
549
|
|
|
return [max(0, $r + $m), max(0, $g + $m), max(0, $b + $m), $alpha]; |
550
|
|
|
} |
551
|
|
|
} elseif (is_array($aColor)) { |
552
|
|
|
if (!isset($aColor[3])) { |
553
|
|
|
$aColor[3] = 0; |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
return $aColor; |
557
|
|
|
} else { |
558
|
|
|
Util\JpGraphError::RaiseL(25079, $aColor, safe_count($aColor)); //(" Unknown color specification: $aColor , size=". safe_count($aColor)); |
559
|
|
|
} |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
// Compare two colors |
563
|
|
|
// return true if equal |
564
|
|
|
public function Equal($aCol1, $aCol2) |
565
|
|
|
{ |
566
|
|
|
$c1 = $this->Color($aCol1); |
567
|
|
|
$c2 = $this->Color($aCol2); |
568
|
|
|
|
569
|
|
|
return $c1[0] == $c2[0] && $c1[1] == $c2[1] && $c1[2] == $c2[2]; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
// Allocate a new color in the current image |
573
|
|
|
// Return new color index, -1 if no more colors could be allocated |
574
|
21 |
|
public function Allocate($aColor, $aAlpha = 0.0) |
575
|
|
|
{ |
576
|
21 |
|
list($r, $g, $b, $a) = $this->color($aColor); |
577
|
|
|
// If alpha is specified in the color string then this |
578
|
|
|
// takes precedence over the second argument |
579
|
21 |
|
if ($a > 0) { |
580
|
|
|
$aAlpha = $a; |
581
|
|
|
} |
582
|
21 |
|
if ($aAlpha < 0 || $aAlpha > 1) { |
583
|
|
|
Util\JpGraphError::RaiseL(25080); //('Alpha parameter for color must be between 0.0 and 1.0'); |
584
|
|
|
} |
585
|
|
|
|
586
|
21 |
|
return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127)); |
|
|
|
|
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
// Try to convert an array with three valid numbers to the corresponding hex array |
590
|
|
|
// This is currenly only used in processing the colors for barplots in order to be able |
591
|
|
|
// to handle the case where the color might be specified as an array of colros as well. |
592
|
|
|
// In that case we must be able to find out if an array of values should be interpretated as |
593
|
|
|
// a single color (specifeid as an RGB triple) |
594
|
|
|
public static function tryHexConversion($aColor) |
595
|
|
|
{ |
596
|
|
|
if (is_array($aColor)) { |
597
|
|
|
if (safe_count($aColor) == 3) { |
598
|
|
|
if (is_numeric($aColor[0]) && is_numeric($aColor[1]) && is_numeric($aColor[2])) { |
599
|
|
|
if (($aColor[0] >= 0 && $aColor[0] <= 255) && |
600
|
|
|
($aColor[1] >= 0 && $aColor[1] <= 255) && |
601
|
|
|
($aColor[2] >= 0 && $aColor[2] <= 255)) { |
602
|
|
|
return sprintf('#%02x%02x%02x', $aColor[0], $aColor[1], $aColor[2]); |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
return $aColor; |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
// Return a RGB tripple corresponding to a position in the normal light spectrum |
612
|
|
|
// The argumen values is in the range [0, 1] where a value of 0 correponds to blue and |
613
|
|
|
// a value of 1 corresponds to red. Values in betwen is mapped to a linear interpolation |
614
|
|
|
// of the constituting colors in the visible color spectra. |
615
|
|
|
// The $aDynamicRange specified how much of the dynamic range we shold use |
616
|
|
|
// a value of 1.0 give the full dyanmic range and a lower value give more dark |
617
|
|
|
// colors. In the extreme of 0.0 then all colors will be black. |
618
|
|
|
public static function GetSpectrum($aVal, $aDynamicRange = 1.0) |
619
|
|
|
{ |
620
|
|
|
if ($aVal < 0 || $aVal > 1.0001) { |
621
|
|
|
return [0, 0, 0]; // Invalid case - just return black |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
$sat = round(255 * $aDynamicRange); |
625
|
|
|
$a = 0.25; |
626
|
|
|
if ($aVal <= 0.25) { |
627
|
|
|
return [0, round($sat * $aVal / $a), $sat]; |
628
|
|
|
} |
629
|
|
|
if ($aVal <= 0.5) { |
630
|
|
|
return [0, $sat, round($sat - $sat * ($aVal - 0.25) / $a)]; |
631
|
|
|
} |
632
|
|
|
if ($aVal <= 0.75) { |
633
|
|
|
return [round($sat * ($aVal - 0.5) / $a), $sat, 0]; |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
return [$sat, round($sat - $sat * ($aVal - 0.75) / $a), 0]; |
637
|
|
|
} |
638
|
|
|
} // @class |
639
|
|
|
|