-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·68 lines (66 loc) · 1.35 KB
/
functions.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
<?php
function makelinks($text,$linkcolor) {
$replacements = "'<a style=\"color:#".$linkcolor.";\" href=\"$1\" target=\"_blank\">$1</a>$4'";
$patterns = "#((http|https|ftp)://(\S*?\.\S*?))(\s|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#ie";
$text = preg_replace($patterns, $replacements, $text);
return $text;
}
function ip_address_to_number($IPaddress) {
if(!$IPaddress) {
return false;
} else {
$ips = split('\.',$IPaddress);
return($ips[3] + $ips[2]*256 + $ips[1]*65536 + $ips[0]*16777216);
}
}
function HSVtoRGB(array $hsv) {
list($H,$S,$V) = $hsv;
//1
$H *= 6;
//2
$I = floor($H);
$F = $H - $I;
//3
$M = $V * (1 - $S);
$N = $V * (1 - $S * $F);
$K = $V * (1 - $S * (1 - $F));
//4
switch ($I) {
case 0:
list($R,$G,$B) = array($V,$K,$M);
break;
case 1:
list($R,$G,$B) = array($N,$V,$M);
break;
case 2:
list($R,$G,$B) = array($M,$V,$K);
break;
case 3:
list($R,$G,$B) = array($M,$N,$V);
break;
case 4:
list($R,$G,$B) = array($K,$M,$V);
break;
case 5:
case 6: //for when $H=1 is given
list($R,$G,$B) = array($V,$M,$N);
break;
}
// converts to HEX
$R = dechex($R * 255);
$G = dechex($G * 255);
$B = dechex($B * 255);
// Adds leading zeros where needed
if ( strlen($R) == 1) {
$R = "0".$R;
}
if ( strlen($G) == 1) {
$G = "0".$G;
}
if ( strlen($B) == 1) {
$B = "0".$B;
}
$RGB = $R.$G.$B;
return $RGB;
}
?>