rgb-naar-hexa-omreken-script
Gesponsorde koppelingen
PHP script bestanden
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
39
40
41
42
43
44
45
46
47
48
49
50
51
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
<?php if($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["r"] >= 0 && $_POST["r"] <= 255 && $_POST["g"] >= 0 && $_POST["g"] <= 255 && $_POST["b"] >= 0 && $_POST["b"] <= 255){
$r2 = $_POST["r"];
$g2 = $_POST["g"];
$b2 = $_POST["b"];
$r = 0;
$g = 0;
$b = 0;
while($r2 > 15){ // Het reken
$r2 = $r2 - 16;
$r++;
}
while($g2 > 15){
$g2 = $g2 - 16;
$g++;
}
while($b2 > 15){
$b2 = $b2 - 16;
$b++;
}
$r = dechex($r);
$r2 = dechex($r2);
$g = dechex($g);
$g2 = dechex($g2);
$b = dechex($b);
$b2 = dechex($b2);
$hexant = $r.$r2.$g.$g2.$b.$b2; // Samenvoegen + Weergeven
if($r == $r2 && $g == $g2 && $b == $b2){ // Veilige kleur check
echo("<table><tr><td align='center' style='text-transform: uppercase;'><b>#$r$g$b</b><br><i>(#$hexant)</i></td><td width=\"30\" height=\"30\" style=\"background: #$hexant;\"></td></tr></table>");
}
else{
echo("<table><tr><td align='center' style='text-transform: uppercase;'><b>#$hexant</b></td><td width=\"30\" height=\"30\" style=\"background: #$hexant;\"></td></tr></table>");
}
}
elseif($_SERVER["REQUEST_METHOD"] == "POST"){ // Error
echo("<font color='red'>Vul correct in!</font>");
}
echo("<p><form action='".$_SERVER["PHP_SELF"]."' method='post'>
R: <input type='text' size='3' maxlength='3' name='r'>
G: <input type='text' size='3' maxlength='3' name='g'>
B: <input type='text' size='3' maxlength='3' name='b'>
<input type='submit' value='Go' name='submit'>
</form></p>"); ?>
$r2 = $_POST["r"];
$g2 = $_POST["g"];
$b2 = $_POST["b"];
$r = 0;
$g = 0;
$b = 0;
while($r2 > 15){ // Het reken
$r2 = $r2 - 16;
$r++;
}
while($g2 > 15){
$g2 = $g2 - 16;
$g++;
}
while($b2 > 15){
$b2 = $b2 - 16;
$b++;
}
$r = dechex($r);
$r2 = dechex($r2);
$g = dechex($g);
$g2 = dechex($g2);
$b = dechex($b);
$b2 = dechex($b2);
$hexant = $r.$r2.$g.$g2.$b.$b2; // Samenvoegen + Weergeven
if($r == $r2 && $g == $g2 && $b == $b2){ // Veilige kleur check
echo("<table><tr><td align='center' style='text-transform: uppercase;'><b>#$r$g$b</b><br><i>(#$hexant)</i></td><td width=\"30\" height=\"30\" style=\"background: #$hexant;\"></td></tr></table>");
}
else{
echo("<table><tr><td align='center' style='text-transform: uppercase;'><b>#$hexant</b></td><td width=\"30\" height=\"30\" style=\"background: #$hexant;\"></td></tr></table>");
}
}
elseif($_SERVER["REQUEST_METHOD"] == "POST"){ // Error
echo("<font color='red'>Vul correct in!</font>");
}
echo("<p><form action='".$_SERVER["PHP_SELF"]."' method='post'>
R: <input type='text' size='3' maxlength='3' name='r'>
G: <input type='text' size='3' maxlength='3' name='g'>
B: <input type='text' size='3' maxlength='3' name='b'>
<input type='submit' value='Go' name='submit'>
</form></p>"); ?>