placemap.class.php
5.61 KB
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
<?php
putenv('GDFONTPATH=' . realpath('.')); // Kerrotaan GD:lle että fontti on samassa hakemistossa
# header("Content-type: image/png"); // lähetetään tiedot
class paikkakartta {
var $i; // imagehandler
var $mp = "1"; // Kerroin
var $main_width = "800";
var $main_height = "600";
var $place_width = "10";
var $place_height = "10";
// Taustan värit
var $bg_r = "255";
var $bg_g = "255";
var $bg_b = "255";
// Vapaan paikan väri
var $p_free_r = "255";
var $p_free_g = "0";
var $p_free_b = "0";
// Varatun paikan väri
var $p_nfree_r = "0";
var $p_nfree_g = "255";
var $p_nfree_b = "0";
// Oman paikan väri
var $p_own_r = "0";
var $p_own_g = "0";
var $p_own_b = "255";
// Infoarean väri
var $info_r = "255";
var $info_g = "0";
var $info_b = "100";
#function __construct() {
# $this->write_base();
#}
/* Kirjotteleepi pohjakartan ja sen reunat jos niin olemme halunneet*/
function write_base() {
header("Content-type: image/png");
$this->main_width = $this->main_width * $this->mp;
$this->main_height = $this->main_height * $this->mp;
$this->i = imagecreate($this->main_width, $this->main_height);
$this->bg_color = imagecolorallocate($this->i, $this->bg_r, $this->bg_g, $this->bg_b); // Taustaväri
$this->black = imagecolorallocate($this->i, 0,0,0);
$this->p_free = imagecolorallocate($this->i, $this->p_free_r, $this->p_free_g, $this->p_free_b);
$this->p_nfree = imagecolorallocate($this->i, $this->p_nfree_r, $this->p_nfree_g, $this->p_nfree_b);
$this->p_own = imagecolorallocate($this->i, $this->p_own_r, $this->p_own_g, $this->p_own_b);
$this->info_color = imagecolorallocate($this->i, $this->info_r, $this->info_g, $this->info_b);
imagefilledrectangle($this->i, 0,0, $this->width, $this->height, $this->bg_color);
}
function create_image() { // Luo itse kuvan, tätä pitää kutsua kun kaikki on luotu.
imagepng($this->i);
imagedestroy($this->i);
}
function write_place($x, $y, $status = NULL) {
if($status == 1) { // jos on oma
$color = $this->p_own;
} elseif($status == 2) {// Jos on varattu
$color = $this->p_nfree;
} else { // muutenhan se on vapaa!
$color = $this->p_free;
}
imagefilledrectangle( // piirretään itse paikka
$this->i,
$x * $this->mp,
$y * $this->mp,
($x + $this->place_width) * $this->mp,
($y + $this->place_height) * $this->mp,
$color);
imageline( // Vasen reunaviiva
$this->i,
$x * $this->mp,
$y * $this->mp,
$x * $this->mp,
($y + $this->place_height) * $this->mp,
$this->black);
imageline( // ylä reunaviiva
$this->i,
$x * $this->mp,
$y * $this->mp,
($x + $this->place_width)* $this->mp,
$y * $this->mp,
$this->black);
imageline( // Ala reunaviiva
$this->i,
($x + $this->place_width) * $this->mp,
($y + $this->place_height) * $this->mp,
$x * $this->mp,
($y + $this->place_height) * $this->mp,
$this->black);
imageline( // oikea reunaviiva
$this->i,
($x + $this->place_width) * $this->mp,
($y + $this->place_height) * $this->mp,
($x + $this->place_width)* $this->mp,
$y * $this->mp,
$this->black);
} // end of func write_place()
function write_info($x, $y, $w, $h, $txt, $color=NULL) { // Piirtää infoneliön
if(!$color) {
$color = $this->info_color;
}
imagefilledrectangle( // piirretään itse paikka
$this->i,
$x * $this->mp,
$y * $this->mp,
($x + $w) * $this->mp,
($y + $h) * $this->mp,
$color);
imageline( // Vasen reunaviiva
$this->i,
$x * $this->mp,
$y * $this->mp,
$x * $this->mp,
($y + $h) * $this->mp,
$this->black);
imageline( // ylä reunaviiva
$this->i,
$x * $this->mp,
$y * $this->mp,
($x + $w)* $this->mp,
$y * $this->mp,
$this->black);
imageline( // Ala reunaviiva
$this->i,
($x + $w) * $this->mp,
($y + $h) * $this->mp,
$x * $this->mp,
($y + $h) * $this->mp,
$this->black);
imageline( // oikea reunaviiva
$this->i,
($x + $w) * $this->mp,
($y + $h) * $this->mp,
($x + $w)* $this->mp,
$y * $this->mp,
$this->black);
imagestring($this->i, 2, ($x + 5) * $this->mp, ($y + 5) * $this->mp, $txt, $this->black);
} // end of func write_info()
function write_text($x, $y, $text, $size=2) {
imagestring($this->i, $size, $x, $y, $text, $this->black);
}
function imagecenteredstring($image, $font_size, $text, $text_color){
$img_w = imagesx($image);
$img_h = imagesy($image);
$text = "$img_w $img_h";
imagestring($image, $font_size, round(($img_w/2)-((strlen($text)*imagefontwidth($font_size))/2), 1), round(($img_h/2)-(imagefontheight($font_size)/2)), $text, $text_color);
}
} // end of class
?>