safecolor-v10
Code (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
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
<?
/*
Function SafeColor();
Programmeur : Frank Schers
Datum : 3 september 2002
Versie : 1.0
Beschrijving :
*/
function SafeColor($hexcolor)
{
if(!eregi("^#", $hexcolor))
$hexcolor = "#".$hexcolor;
if(eregi("^#[a-f0-9]{6}$", $hexcolor)){
$color[0] = hexdec(substr($hexcolor,1,2)); // red
$color[1] = hexdec(substr($hexcolor,3,2)); //green
$color[2] = hexdec(substr($hexcolor,5,2)); //blue
for($i=0; $i<count($color); $i++)
{
$mod = $color[$i]%51;
if($mod>26)
$hex[$i] = str_pad(dechex($color[$i] + (51-$mod)),2,0,STR_PAD_LEFT);
else
$hex[$i] = str_pad(dechex($color[$i] - $mod),2,0,STR_PAD_LEFT);
}
$safecolor = strtoupper("#".$hex[0].$hex[1].$hex[2]);
return $safecolor;
}
else
{
return $hexcolor;
}
}
?>
/*
Function SafeColor();
Programmeur : Frank Schers
Datum : 3 september 2002
Versie : 1.0
Beschrijving :
*/
function SafeColor($hexcolor)
{
if(!eregi("^#", $hexcolor))
$hexcolor = "#".$hexcolor;
if(eregi("^#[a-f0-9]{6}$", $hexcolor)){
$color[0] = hexdec(substr($hexcolor,1,2)); // red
$color[1] = hexdec(substr($hexcolor,3,2)); //green
$color[2] = hexdec(substr($hexcolor,5,2)); //blue
for($i=0; $i<count($color); $i++)
{
$mod = $color[$i]%51;
if($mod>26)
$hex[$i] = str_pad(dechex($color[$i] + (51-$mod)),2,0,STR_PAD_LEFT);
else
$hex[$i] = str_pad(dechex($color[$i] - $mod),2,0,STR_PAD_LEFT);
}
$safecolor = strtoupper("#".$hex[0].$hex[1].$hex[2]);
return $safecolor;
}
else
{
return $hexcolor;
}
}
?>