forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pImage.class.php
577 lines (498 loc) · 18.6 KB
/
pImage.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
<?php
/*
pDraw - pChart core class
Version : 2.1.4
Made by : Jean-Damien POGOLOTTI
Last Update : 19/01/2014
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
/* The GD extension is mandatory */
if (!extension_loaded('gd') && !extension_loaded('gd2')) {
echo "GD extension must be loaded. \r\n";
exit();
}
/* Image map handling */
define("IMAGE_MAP_STORAGE_FILE", 680001);
define("IMAGE_MAP_STORAGE_SESSION", 680002);
/* Last generated chart layout */
define("CHART_LAST_LAYOUT_REGULAR", 680011);
define("CHART_LAST_LAYOUT_STACKED", 680012);
/* ImageMap string delimiter */
define("IMAGE_MAP_DELIMITER", chr(1));
class pImage extends pDraw
{
/* Image settings, size, quality, .. */
var $XSize = NULL; // Width of the picture
var $YSize = NULL; // Height of the picture
var $Picture = NULL; // GD picture object
var $Antialias = TRUE; // Turn antialias on or off
var $AntialiasQuality = 0; // Quality of the antialiasing implementation (0-1)
// var $Mask = ""; // Already drawn pixels mask (Filled circle implementation) # UNUSED
var $TransparentBackground = FALSE; // Just to know if we need to flush the alpha channels when rendering
/* Graph area settings */
var $GraphAreaX1 = NULL; // Graph area X origin
var $GraphAreaY1 = NULL; // Graph area Y origin
var $GraphAreaX2 = NULL; // Graph area bottom right X position
var $GraphAreaY2 = NULL; // Graph area bottom right Y position
/* Scale settings */
var $ScaleMinDivHeight = 20; // Minimum height for scame divs
/* Font properties */
var $FontName = "fonts/GeosansLight.ttf"; // Default font file
var $FontSize = 12; // Default font size
var $FontBox = NULL; // Return the bounding box of the last written string
var $FontColorR = 0; // Default color settings
var $FontColorG = 0; // Default color settings
var $FontColorB = 0; // Default color settings
var $FontColorA = 100; // Default transparency
/* Shadow properties */
var $Shadow = FALSE; // Turn shadows on or off
var $ShadowX = NULL; // X Offset of the shadow
var $ShadowY = NULL; // Y Offset of the shadow
var $ShadowR = NULL; // R component of the shadow
var $ShadowG = NULL; // G component of the shadow
var $ShadowB = NULL; // B component of the shadow
var $Shadowa = NULL; // Alpha level of the shadow
/* Image map */
var $ImageMap = NULL; // Aray containing the image map
var $ImageMapIndex = "pChart"; // Name of the session array
var $ImageMapStorageMode = NULL; // Save the current imagemap storage mode
var $ImageMapAutoDelete = TRUE; // Automatic deletion of the image map temp files
/* Data Set */
var $DataSet = NULL; // Attached dataset
/* Last generated chart info */
var $LastChartLayout = CHART_LAST_LAYOUT_REGULAR; // Last layout : regular or stacked
/* Class constructor */
function __construct($XSize, $YSize, $DataSet = NULL, $TransparentBackground = FALSE)
{
$this->TransparentBackground = $TransparentBackground;
if ($DataSet != NULL) {
$this->DataSet = $DataSet;
}
$this->XSize = $XSize;
$this->YSize = $YSize;
$this->Picture = imagecreatetruecolor($XSize, $YSize);
if ($this->TransparentBackground) {
imagealphablending($this->Picture, FALSE);
imagefilledrectangle($this->Picture, 0, 0, $XSize, $YSize, imagecolorallocatealpha($this->Picture, 255, 255, 255, 127));
imagealphablending($this->Picture, TRUE);
imagesavealpha($this->Picture, true);
} else {
imagefilledrectangle($this->Picture, 0, 0, $XSize, $YSize, $this->AllocateColor(255, 255, 255));
}
}
function __destruct(){
imagedestroy($this->Picture);
}
/* Enable / Disable and set shadow properties */
function setShadow($Enabled = TRUE, array $Format = [])
{
$X = 2;
$Y = 2;
$R = 0;
$G = 0;
$B = 0;
$Alpha = 10;
/* Override defaults */
extract($Format);
$this->Shadow = $Enabled;
$this->ShadowX = $X;
$this->ShadowY = $Y;
$this->ShadowR = $R;
$this->ShadowG = $G;
$this->ShadowB = $B;
$this->Shadowa = $Alpha;
if ($this->ShadowX == 0 || $this->ShadowY == 0){
die("Invalid shadow specs");
}
}
/* Set the graph area position */
function setGraphArea($X1, $Y1, $X2, $Y2)
{
if ($X2 < $X1 || $X1 == $X2 || $Y2 < $Y1 || $Y1 == $Y2) {
return -1;
}
$this->GraphAreaX1 = $X1;
$this->DataSet->Data["GraphArea"]["X1"] = $X1;
$this->GraphAreaY1 = $Y1;
$this->DataSet->Data["GraphArea"]["Y1"] = $Y1;
$this->GraphAreaX2 = $X2;
$this->DataSet->Data["GraphArea"]["X2"] = $X2;
$this->GraphAreaY2 = $Y2;
$this->DataSet->Data["GraphArea"]["Y2"] = $Y2;
}
/* Return the width of the picture */
function getWidth()
{
return $this->XSize;
}
/* Return the heigth of the picture */
function getHeight()
{
return $this->YSize;
}
/* Render the picture to a file */
function render($FileName)
{
if ($this->TransparentBackground) {
imagealphablending($this->Picture, false);
imagesavealpha($this->Picture, true);
}
imagepng($this->Picture, $FileName);
}
/* Render the picture to a web browser stream */
function stroke($BrowserExpire = FALSE)
{
if ($this->TransparentBackground) {
imagealphablending($this->Picture, false);
imagesavealpha($this->Picture, true);
}
if ($BrowserExpire) {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
}
header('Content-type: image/png');
imagepng($this->Picture);
}
/* Automatic output method based on the calling interface */
function autoOutput($FileName = "output.png")
{
if (php_sapi_name() == "cli") {
$this->Render($FileName);
} else {
$this->Stroke();
}
}
/* Return the length between two points */
function getLength($X1, $Y1, $X2, $Y2)
{
return (sqrt(pow(max($X1, $X2) - min($X1, $X2), 2) + pow(max($Y1, $Y2) - min($Y1, $Y2), 2)));
}
/* Return the orientation of a line */
function getAngle($X1, $Y1, $X2, $Y2)
{
$Opposite = $Y2 - $Y1;
$Adjacent = $X2 - $X1;
$Angle = rad2deg(atan2($Opposite, $Adjacent));
return (($Angle > 0) ? $Angle : (360 - abs($Angle)));
}
/* Return the surrounding box of text area */
function getTextBox_deprecated($X, $Y, $FontName, $FontSize, $Angle, $Text)
{
$Size = imagettfbbox($FontSize, $Angle, realpath($FontName), $Text);
$Width = $this->getLength($Size[0], $Size[1], $Size[2], $Size[3]) + 1;
$Height = $this->getLength($Size[2], $Size[3], $Size[4], $Size[5]) + 1;
$RealPos[0]["X"] = $X;
$RealPos[0]["Y"] = $Y;
$RealPos[1]["X"] = cos((360 - $Angle) * PI / 180) * $Width + $RealPos[0]["X"];
$RealPos[1]["Y"] = sin((360 - $Angle) * PI / 180) * $Width + $RealPos[0]["Y"];
$RealPos[2]["X"] = cos((270 - $Angle) * PI / 180) * $Height + $RealPos[1]["X"];
$RealPos[2]["Y"] = sin((270 - $Angle) * PI / 180) * $Height + $RealPos[1]["Y"];
$RealPos[3]["X"] = cos((180 - $Angle) * PI / 180) * $Width + $RealPos[2]["X"];
$RealPos[3]["Y"] = sin((180 - $Angle) * PI / 180) * $Width + $RealPos[2]["Y"];
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"];
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"];
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
return $RealPos;
}
/* Return the surrounding box of text area */
function getTextBox($X, $Y, $FontName, $FontSize, $Angle, $Text)
{
$coords = imagettfbbox($FontSize, 0, realpath($FontName), $Text);
$a = deg2rad($Angle);
$ca = cos($a);
$sa = sin($a);
$RealPos = [];
for ($i = 0; $i < 7; $i+= 2) {
$RealPos[$i / 2]["X"] = $X + round($coords[$i] * $ca + $coords[$i + 1] * $sa);
$RealPos[$i / 2]["Y"] = $Y + round($coords[$i + 1] * $ca - $coords[$i] * $sa);
}
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"];
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"];
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
$RealPos[TEXT_ALIGN_TOPLEFT]["X"] = $RealPos[3]["X"];
$RealPos[TEXT_ALIGN_TOPLEFT]["Y"] = $RealPos[3]["Y"];
$RealPos[TEXT_ALIGN_TOPRIGHT]["X"] = $RealPos[2]["X"];
$RealPos[TEXT_ALIGN_TOPRIGHT]["Y"] = $RealPos[2]["Y"];
$RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["X"] = ($RealPos[1]["X"] - $RealPos[0]["X"]) / 2 + $RealPos[0]["X"];
$RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["Y"] = ($RealPos[0]["Y"] - $RealPos[1]["Y"]) / 2 + $RealPos[1]["Y"];
$RealPos[TEXT_ALIGN_TOPMIDDLE]["X"] = ($RealPos[2]["X"] - $RealPos[3]["X"]) / 2 + $RealPos[3]["X"];
$RealPos[TEXT_ALIGN_TOPMIDDLE]["Y"] = ($RealPos[3]["Y"] - $RealPos[2]["Y"]) / 2 + $RealPos[2]["Y"];
$RealPos[TEXT_ALIGN_MIDDLELEFT]["X"] = ($RealPos[0]["X"] - $RealPos[3]["X"]) / 2 + $RealPos[3]["X"];
$RealPos[TEXT_ALIGN_MIDDLELEFT]["Y"] = ($RealPos[0]["Y"] - $RealPos[3]["Y"]) / 2 + $RealPos[3]["Y"];
$RealPos[TEXT_ALIGN_MIDDLERIGHT]["X"] = ($RealPos[1]["X"] - $RealPos[2]["X"]) / 2 + $RealPos[2]["X"];
$RealPos[TEXT_ALIGN_MIDDLERIGHT]["Y"] = ($RealPos[1]["Y"] - $RealPos[2]["Y"]) / 2 + $RealPos[2]["Y"];
$RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["X"] = ($RealPos[1]["X"] - $RealPos[3]["X"]) / 2 + $RealPos[3]["X"];
$RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["Y"] = ($RealPos[0]["Y"] - $RealPos[2]["Y"]) / 2 + $RealPos[2]["Y"];
return $RealPos;
}
/* Set current font properties */
function setFontProperties(array $Format = [])
{
$R = -1;
$G = -1;
$B = -1;
$Alpha = 100;
$FontName = NULL;
$FontSize = NULL;
/* Override defaults */
extract($Format);
($R != - 1) AND $this->FontColorR = $R;
($G != - 1) AND $this->FontColorG = $G;
($B != - 1) AND $this->FontColorB = $B;
($Alpha != NULL) AND $this->FontColorA = $Alpha;
($FontName != NULL) AND $this->FontName = $FontName;
($FontSize != NULL) AND $this->FontSize = $FontSize;
}
/* Returns the 1st decimal values (used to correct AA bugs) */
function getFirstDecimal($Value)
{
$Values = explode(".", $Value);
return (isset($Values[1])) ? substr($Values[1], 0, 1) : 0;
}
/* Attach a dataset to your pChart Object */
function setDataSet(&$DataSet)
{
$this->DataSet = $DataSet;
}
/* Print attached dataset contents to STDOUT */
function printDataSet()
{
print_r($this->DataSet);
}
/* Initialise the image map methods */
function initialiseImageMap($Name = "pChart", $StorageMode = IMAGE_MAP_STORAGE_SESSION, $UniqueID = "imageMap", $StorageFolder = "tmp")
{
$this->ImageMapIndex = $Name;
$this->ImageMapStorageMode = $StorageMode;
if ($StorageMode == IMAGE_MAP_STORAGE_SESSION) {
if (!isset($_SESSION)) {
session_start();
}
$_SESSION[$this->ImageMapIndex] = NULL;
} elseif ($StorageMode == IMAGE_MAP_STORAGE_FILE) {
$this->ImageMapFileName = $UniqueID;
$this->ImageMapStorageFolder = $StorageFolder;
if (file_exists($StorageFolder . "/" . $UniqueID . ".map")) {
unlink($StorageFolder . "/" . $UniqueID . ".map");
}
}
}
/* Add a zone to the image map */
function addToImageMap($Type, $Plots, $Color = NULL, $Title = NULL, $Message = NULL, $HTMLEncode = FALSE)
{
if ($this->ImageMapStorageMode == NULL) {
$this->initialiseImageMap();
}
/* Encode the characters in the imagemap in HTML standards */
$Title = str_replace("€", "\u20AC", $Title); # Momchil TODO TEST THIS
$Title = htmlentities($Title, ENT_QUOTES); #, "ISO-8859-15"); # As of PHP 5.6 The default value for the encoding parameter = the default_charset config option.
if ($HTMLEncode) {
$Message = htmlentities($Message, ENT_QUOTES); #, "ISO-8859-15");
#$Message = str_replace("<", "<", $Message); # Seems covered Example #1 A htmlentities() example
#$Message = str_replace(">", ">", $Message); # http://php.net/manual/en/function.htmlentities.php
}
if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
if (!isset($_SESSION)) {
$this->initialiseImageMap();
}
$_SESSION[$this->ImageMapIndex][] = [$Type,$Plots,$Color,$Title,$Message];
} elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", 'a');
fwrite($Handle, $Type . IMAGE_MAP_DELIMITER . $Plots . IMAGE_MAP_DELIMITER . $Color . IMAGE_MAP_DELIMITER . $Title . IMAGE_MAP_DELIMITER . $Message . "\r\n");
fclose($Handle);
}
}
/* Remove VOID values from an imagemap custom values array */
function removeVOIDFromArray($SerieName, array $Values)
{
if (!isset($this->DataSet->Data["Series"][$SerieName])) {
return -1;
}
$Result = [];
foreach($this->DataSet->Data["Series"][$SerieName]["Data"] as $Key => $Value) {
if ($Value != VOID && isset($Values[$Key])) {
$Result[] = $Values[$Key];
}
}
return $Result;
}
/* Replace the title of one image map serie */
function replaceImageMapTitle($OldTitle, $NewTitle)
{
if ($this->ImageMapStorageMode == NULL) {
return -1;
}
if (is_array($NewTitle)) {
$NewTitle = $this->removeVOIDFromArray($OldTitle, $NewTitle);
}
if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
if (!isset($_SESSION)) {
return -1;
}
if (is_array($NewTitle)) {
$ID = 0;
foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) {
if ($Settings[3] == $OldTitle && isset($NewTitle[$ID])) {
$_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle[$ID];
$ID++;
}
}
} else {
foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) {
if ($Settings[3] == $OldTitle) {
$_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle;
}
}
}
} elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
$TempArray = [];
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", "r");
if ($Handle) {
while (($Buffer = fgets($Handle, 4096)) !== false) {
$Fields = preg_split("/" . IMAGE_MAP_DELIMITER . "/", str_replace([chr(10), chr(13)], "", $Buffer));
$TempArray[] = [$Fields[0], $Fields[1], $Fields[2], $Fields[3], $Fields[4]];
}
fclose($Handle);
if (is_array($NewTitle)) {
$ID = 0;
foreach($TempArray as $Key => $Settings) {
if ($Settings[3] == $OldTitle && isset($NewTitle[$ID])) {
$TempArray[$Key][3] = $NewTitle[$ID];
$ID++;
}
}
} else {
foreach($TempArray as $Key => $Settings) {
if ($Settings[3] == $OldTitle) {
$TempArray[$Key][3] = $NewTitle;
}
}
}
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", 'w');
foreach($TempArray as $Key => $Settings) {
fwrite($Handle, $Settings[0] . IMAGE_MAP_DELIMITER . $Settings[1] . IMAGE_MAP_DELIMITER . $Settings[2] . IMAGE_MAP_DELIMITER . $Settings[3] . IMAGE_MAP_DELIMITER . $Settings[4] . "\r\n");
}
fclose($Handle);
}
}
}
/* Replace the values of the image map contents */
function replaceImageMapValues($Title, array $Values)
{
if ($this->ImageMapStorageMode == NULL) {
return -1;
}
$Values = $this->removeVOIDFromArray($Title, $Values);
$ID = 0;
if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
if (!isset($_SESSION)) {
return -1;
}
foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) {
if ($Settings[3] == $Title) {
if (isset($Values[$ID])) {
$_SESSION[$this->ImageMapIndex][$Key][4] = $Values[$ID];
}
$ID++;
}
}
} elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
$TempArray = [];
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", "r");
if ($Handle) {
while (($Buffer = fgets($Handle, 4096)) !== false) {
$Fields = preg_split("/" . IMAGE_MAP_DELIMITER . "/", str_replace([chr(10), chr(13)], "", $Buffer));
$TempArray[] = [$Fields[0], $Fields[1], $Fields[2], $Fields[3], $Fields[4]];
}
fclose($Handle);
foreach($TempArray as $Key => $Settings) {
if ($Settings[3] == $Title) {
if (isset($Values[$ID])) {
$TempArray[$Key][4] = $Values[$ID];
}
$ID++;
}
}
$Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", 'w');
foreach($TempArray as $Key => $Settings) {
fwrite($Handle, $Settings[0] . IMAGE_MAP_DELIMITER . $Settings[1] . IMAGE_MAP_DELIMITER . $Settings[2] . IMAGE_MAP_DELIMITER . $Settings[3] . IMAGE_MAP_DELIMITER . $Settings[4] . "\r\n");
}
fclose($Handle);
}
}
}
/* Dump the image map */
function dumpImageMap($Name = "pChart", $StorageMode = IMAGE_MAP_STORAGE_SESSION, $UniqueID = "imageMap", $StorageFolder = "tmp")
{
$this->ImageMapIndex = $Name;
$this->ImageMapStorageMode = $StorageMode;
if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
if (!isset($_SESSION)) {
session_start();
}
if ($_SESSION[$Name] != NULL) {
foreach($_SESSION[$Name] as $Key => $Params) {
echo $Params[0] . IMAGE_MAP_DELIMITER . $Params[1] . IMAGE_MAP_DELIMITER . $Params[2] . IMAGE_MAP_DELIMITER . $Params[3] . IMAGE_MAP_DELIMITER . $Params[4] . "\r\n";
}
}
} elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
if (file_exists($StorageFolder . "/" . $UniqueID . ".map")) {
$Handle = fopen($StorageFolder . "/" . $UniqueID . ".map", "r");
if ($Handle) {
while (($Buffer = fgets($Handle, 4096)) !== false) {
echo $Buffer;
}
}
fclose($Handle);
if ($this->ImageMapAutoDelete) {
unlink($StorageFolder . "/" . $UniqueID . ".map");
}
}
}
/* When the image map is returned to the client, the script ends */
exit();
}
/* Return the HTML converted color from the RGB composite values */
function toHTMLColor($R, $G, $B) # Momchil: Not worth caching
{
$R = dechex(max(min(255, $R), 0));
$G = dechex(max(min(255, $G), 0));
$B = dechex(max(min(255, $B), 0));
$Color = "#" . (strlen($R) < 2 ? '0' : '') . $R;
$Color.= (strlen($G) < 2 ? '0' : '') . $G;
$Color.= (strlen($B) < 2 ? '0' : '') . $B;
return $Color;
}
/* Reverse an array of points */
function reversePlots($Plots)
{
$Result = [];
for ($i = count($Plots) - 2; $i >= 0; $i = $i - 2) {
$Result[] = $Plots[$i];
$Result[] = $Plots[$i + 1];
}
return $Result;
}
/* Mirror Effect */
function drawAreaMirror($X, $Y, $Width, $Height, array $Format = [])
{
$StartAlpha = isset($Format["StartAlpha"]) ? $Format["StartAlpha"] : 80;
$EndAlpha = isset($Format["EndAlpha"]) ? $Format["EndAlpha"] : 0;
$AlphaStep = ($StartAlpha - $EndAlpha) / $Height;
$Picture = imagecreatetruecolor($this->XSize, $this->YSize);
imagecopy($Picture, $this->Picture, 0, 0, 0, 0, $this->XSize, $this->YSize);
for ($i = 1; $i <= $Height; $i++) {
if ($Y + ($i - 1) < $this->YSize && $Y - $i > 0) {
imagecopymerge($Picture, $this->Picture, $X, $Y + ($i - 1), $X, $Y - $i, $Width, 1, $StartAlpha - $AlphaStep * $i);
}
}
imagecopy($this->Picture, $Picture, 0, 0, 0, 0, $this->XSize, $this->YSize);
imagedestroy($Picture);
}
}
?>