-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleDrawing.php
210 lines (181 loc) · 4.16 KB
/
SimpleDrawing.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/**
* SimpleDrawing class.
*
* @author Ivanov Georgiy <[email protected]>
* @copyright 2013
* @license GPL
* @package component
*/
class SimpleDrawing extends SimpleImage
{
private $color = array(0,0,0,0);
/**
* Get current color info
*
* @return type
*/
public function getColor()
{
return $this->color;
}
/**
* Get gd color from color
*
* @return type
*/
public function getGDColor()
{
@list($red, $green, $blue, $alpha) = $this->color;
return ($alpha == 0) ?
imagecolorallocate($this->image, $red, $green, $blue) :
imagecolorallocatealpha($this->image, $red, $green, $blue, $alpha);
}
/**
* Set current color
*
* @param array $color
* @return \SimpleDrawing
*/
public function setColor($color)
{
$this->color = $color;
return $this;
}
/**
* Draw line from $x1, $y2 to $x2, $y2
*
* @param type $x1
* @param type $y1
* @param type $x2
* @param type $y2
* @return \SimpleDrawing
*/
public function line($x1, $y1, $x2, $y2)
{
imageline($this->image, $x1, $y1, $x2, $y2, $this->getGDColor($this->color));
return $this;
}
/**
* Draw Rect from $x1, $y1 on $w, $h
*
* @param type $x1
* @param type $y1
* @param type $w
* @param type $h
* @return \SimpleDrawing
*/
public function rect($x1, $y1, $w, $h)
{
imagerectangle($this->image, $x1, $y1, $x1+$w, $y1+$h, $this->getGDColor($this->color));
return $this;
}
/**
* Fill rectangle from $x1, $y2 on $w, $h
*
* @param type $x1
* @param type $y1
* @param type $w
* @param type $h
* @return \SimpleDrawing
*/
public function filledRect($x1, $y1, $w, $h)
{
imagefilledrectangle($this->image, $x1, $y1, $x1+$w, $y1+$h, $this->getGDColor($this->color));
return $this;
}
/**
*
* Draw ellipse $x, $y to $w, $h
*
* @param type $x
* @param type $y
* @param type $w
* @param type $h
* @return \SimpleDrawing
*/
public function ellipse($x, $y, $w, $h)
{
imageellipse($this->image, $x, $y, $w, $h, $this->getGDColor($this->color));
return $this;
}
/**
* Draw filled ellispse
*
* @param type $x
* @param type $y
* @param type $w
* @param type $h
* @return \SimpleDrawing
*/
public function filledEllipse($x, $y, $w, $h)
{
imagefilledellipse($this->image, $x, $y, $w, $h, $this->getGDColor($this->color));
return $this;
}
/**
* Draw circle
*
* @param type $x
* @param type $y
* @param type $w
* @return type
*/
public function circle($x, $y, $w)
{
return $this->ellipse($x, $y, $w, $w);
}
/**
* Draw filled circle
*
* @param type $x
* @param type $y
* @param type $w
* @return type
*/
public function filledCircle($x, $y, $w)
{
return $this->filledEllipse($x, $y, $w, $w);
}
/**
* Fill image by rectangle
*
* @return type
*/
public function fill($x = 0, $y = 0)
{
return $this->filledRect($x, $y, $this->getWidth(), $this->getHeight());
}
/**
* Get pixel color
*
* @return type
*/
public function getPixel($x, $y)
{
return array_values(imagecolorsforindex($this->image, imagecolorat($this->image, $x, $y)));
}
/**
* Set pixel color
*
* @return type
*/
public function setPixel($x, $y)
{
return imagesetpixel($this->image, $x, $y , $this->getGDColor($this->color));
}
/**
* Create new GD image
*
* @param type $width
* @param type $height
* @return \SimpleDrawing
*/
public function create($width, $height)
{
$img = imagecreatetruecolor($width, $height);
$this->load($img);
return $this;
}
}
?>