forked from ph2lb/LoRaWAN_TTN_Env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttnlora_env_marker.php
63 lines (53 loc) · 1.72 KB
/
ttnlora_env_marker.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
<?php
$color = isset($_GET['c']) ? $_GET['c'] : "1A88AB";
$text = isset($_GET['t']) ? $_GET['t'] : "-99";
$fillcolor = explode(",",hex2rgb($color));
$IMG = imagecreate( 30, 30 );
$background = imagecolorallocate($IMG, 255,255,255);
$text_color = imagecolorallocate($IMG, 0,0,0);
if ($color == '000000')
$text_color = imagecolorallocate($IMG, 255,0,0);
$dot_color = imagecolorallocate($IMG, $fillcolor[0],$fillcolor[1],$fillcolor[2]);
imagecolortransparent ( $IMG, $background );
imagefilledellipse( $IMG, 15, 15, 30, 30, $dot_color );
imageellipse( $IMG, 15, 15, 29, 29, $text_color );
$text_x = 8;
$text_y = 8;
if (strlen($text) == 1)
$text_x += 4;
if (strlen($text) == 3)
$text_x -= 3;
imagestring( $IMG, 3, $text_x, $text_y, $text, $text_color );
header( "Content-type: image/png" );
imagepng($IMG);
imagecolordeallocate($IMG, $line_color );
imagecolordeallocate($IMG, $text_color );
imagecolordeallocate($IMG, $background );
imagedestroy($IMG);
exit;
function hex2rgb($hex) {
// Copied
$hex = str_replace("#", "", $hex);
switch (strlen($hex)) {
case 1:
$hex = $hex.$hex;
case 2:
$r = hexdec($hex);
$g = hexdec($hex);
$b = hexdec($hex);
break;
case 3:
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
break;
default:
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
break;
}
$rgb = array($r, $g, $b);
return implode(",", $rgb);
}
?>