1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This file is part of the O2System Framework package.
|
4
|
|
|
*
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE
|
6
|
|
|
* file that was distributed with this source code.
|
7
|
|
|
*
|
8
|
|
|
* @author Steeve Andrian Salim
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim
|
10
|
|
|
*/
|
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------
|
13
|
|
|
|
14
|
|
|
namespace O2System\Image\Watermark;
|
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------
|
17
|
|
|
|
18
|
|
|
use O2System\Image\Abstracts\AbstractWatermark;
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* Class Text
|
22
|
|
|
*
|
23
|
|
|
* @package O2System\Image\Watermark
|
24
|
|
|
*/
|
25
|
|
|
class Text extends AbstractWatermark
|
26
|
|
|
{
|
27
|
|
|
/**
|
28
|
|
|
* Text::$fontTruetype
|
29
|
|
|
*
|
30
|
|
|
* Text use truetype font flag.
|
31
|
|
|
*
|
32
|
|
|
* @var bool
|
33
|
|
|
*/
|
34
|
|
|
protected $fontTruetype = true;
|
35
|
|
|
|
36
|
|
|
/**
|
37
|
|
|
* Text::$fontPath
|
38
|
|
|
*
|
39
|
|
|
* Text font path.
|
40
|
|
|
*
|
41
|
|
|
* @var string
|
42
|
|
|
*/
|
43
|
|
|
protected $fontPath;
|
44
|
|
|
|
45
|
|
|
/**
|
46
|
|
|
* Text::$fontSize
|
47
|
|
|
*
|
48
|
|
|
* Text font size.
|
49
|
|
|
*
|
50
|
|
|
* @var int
|
51
|
|
|
*/
|
52
|
|
|
protected $fontSize;
|
53
|
|
|
|
54
|
|
|
/**
|
55
|
|
|
* Text::$fontColor
|
56
|
|
|
*
|
57
|
|
|
* Text font color.
|
58
|
|
|
*
|
59
|
|
|
* @var string
|
60
|
|
|
*/
|
61
|
|
|
protected $fontColor = 'ffffff';
|
62
|
|
|
|
63
|
|
|
/**
|
64
|
|
|
* Text::$string
|
65
|
|
|
*
|
66
|
|
|
* Text string content.
|
67
|
|
|
*
|
68
|
|
|
* @var string
|
69
|
|
|
*/
|
70
|
|
|
protected $string;
|
71
|
|
|
|
72
|
|
|
/**
|
73
|
|
|
* Text::$angle
|
74
|
|
|
*
|
75
|
|
|
* Text angle.
|
76
|
|
|
*
|
77
|
|
|
* @var int
|
78
|
|
|
*/
|
79
|
|
|
protected $angle = 0;
|
80
|
|
|
|
81
|
|
|
// ------------------------------------------------------------------------
|
82
|
|
|
|
83
|
|
|
/**
|
84
|
|
|
* Text::signature
|
85
|
|
|
*
|
86
|
|
|
* Create a signature text image watermark with Jellyka Saint-Andrew's Queen Truetype Font.
|
87
|
|
|
*
|
88
|
|
|
* @param string $string
|
89
|
|
|
* @param int $size
|
90
|
|
|
* @param string $color
|
91
|
|
|
*
|
92
|
|
|
* @return static
|
93
|
|
|
*/
|
94
|
|
|
public function signature($string, $size = 25, $color = 'ffffff')
|
95
|
|
|
{
|
96
|
|
|
$this->setFontPath(__DIR__ . DIRECTORY_SEPARATOR . 'Fonts/Jellyka_Saint-Andrew\'s_Queen.ttf')
|
97
|
|
|
->setFontSize($size)
|
98
|
|
|
->setFontColor($color)
|
99
|
|
|
->setString($string);
|
100
|
|
|
|
101
|
|
|
if ($this->position === 'AUTO') {
|
102
|
|
|
$this->position = 'CENTER';
|
103
|
|
|
}
|
104
|
|
|
|
105
|
|
|
return $this;
|
106
|
|
|
}
|
107
|
|
|
|
108
|
|
|
// ------------------------------------------------------------------------
|
109
|
|
|
|
110
|
|
|
/**
|
111
|
|
|
* Text::copyright
|
112
|
|
|
*
|
113
|
|
|
* Create a copyright text image watermark with Express Way Regular Truetype Font.
|
114
|
|
|
*
|
115
|
|
|
* @param string $string
|
116
|
|
|
* @param int $size
|
117
|
|
|
* @param string $color
|
118
|
|
|
*
|
119
|
|
|
* @return $this
|
120
|
|
|
*/
|
121
|
|
|
public function copyright($string, $size = 10, $color = 'ffffff')
|
122
|
|
|
{
|
123
|
|
|
$this->setFontPath(__DIR__ . DIRECTORY_SEPARATOR . 'Fonts/ExpresswayRg-Regular.ttf')
|
124
|
|
|
->setFontSize($size)
|
125
|
|
|
->setFontColor($color)
|
126
|
|
|
->setString($string);
|
127
|
|
|
|
128
|
|
|
if ($this->position === 'AUTO') {
|
129
|
|
|
$this->position = 'BOTTOM_LEFT';
|
130
|
|
|
}
|
131
|
|
|
|
132
|
|
|
return $this;
|
133
|
|
|
}
|
134
|
|
|
|
135
|
|
|
// ------------------------------------------------------------------------
|
136
|
|
|
|
137
|
|
|
/**
|
138
|
|
|
* Text::getFontPath
|
139
|
|
|
*
|
140
|
|
|
* Gets text font path.
|
141
|
|
|
*
|
142
|
|
|
* @return string
|
143
|
|
|
*/
|
144
|
|
|
public function getFontPath()
|
145
|
|
|
{
|
146
|
|
|
return $this->fontPath;
|
147
|
|
|
}
|
148
|
|
|
|
149
|
|
|
// -------------------------------------------------------------------------
|
150
|
|
|
|
151
|
|
|
/**
|
152
|
|
|
* Text::setFontPath
|
153
|
|
|
*
|
154
|
|
|
* Sets text font path.
|
155
|
|
|
*
|
156
|
|
|
* @param $fontPath
|
157
|
|
|
*
|
158
|
|
|
* @return $this
|
159
|
|
|
*/
|
160
|
|
|
public function setFontPath($fontPath)
|
161
|
|
|
{
|
162
|
|
|
if (is_file($fontPath)) {
|
163
|
|
|
$this->fontTruetype = true;
|
164
|
|
|
$this->fontPath = $fontPath;
|
165
|
|
|
}
|
166
|
|
|
|
167
|
|
|
return $this;
|
168
|
|
|
}
|
169
|
|
|
|
170
|
|
|
// ------------------------------------------------------------------------
|
171
|
|
|
|
172
|
|
|
/**
|
173
|
|
|
* Text::getFontSize
|
174
|
|
|
*
|
175
|
|
|
* Gets text font size.
|
176
|
|
|
*
|
177
|
|
|
* @return int
|
178
|
|
|
*/
|
179
|
|
|
public function getFontSize()
|
180
|
|
|
{
|
181
|
|
|
return $this->fontSize;
|
182
|
|
|
}
|
183
|
|
|
|
184
|
|
|
// ------------------------------------------------------------------------
|
185
|
|
|
|
186
|
|
|
public function setFontSize($fontSize)
|
187
|
|
|
{
|
188
|
|
|
$this->fontSize = (int)$fontSize;
|
189
|
|
|
|
190
|
|
|
return $this;
|
191
|
|
|
}
|
192
|
|
|
|
193
|
|
|
// ------------------------------------------------------------------------
|
194
|
|
|
|
195
|
|
|
/**
|
196
|
|
|
* Text::getFontColor
|
197
|
|
|
*
|
198
|
|
|
* Gets text font color.
|
199
|
|
|
*
|
200
|
|
|
* @return string
|
201
|
|
|
*/
|
202
|
|
|
public function getFontColor()
|
203
|
|
|
{
|
204
|
|
|
return $this->fontColor;
|
205
|
|
|
}
|
206
|
|
|
|
207
|
|
|
// ------------------------------------------------------------------------
|
208
|
|
|
|
209
|
|
|
public function setFontColor($fontColor)
|
210
|
|
|
{
|
211
|
|
|
$this->fontColor = '#' . ltrim($fontColor, '#');
|
212
|
|
|
|
213
|
|
|
return $this;
|
214
|
|
|
}
|
215
|
|
|
|
216
|
|
|
// ------------------------------------------------------------------------
|
217
|
|
|
|
218
|
|
|
/**
|
219
|
|
|
* Text::getString
|
220
|
|
|
*
|
221
|
|
|
* Gets text string.
|
222
|
|
|
*
|
223
|
|
|
* @return string
|
224
|
|
|
*/
|
225
|
|
|
public function getString()
|
226
|
|
|
{
|
227
|
|
|
return $this->string;
|
228
|
|
|
}
|
229
|
|
|
|
230
|
|
|
// ------------------------------------------------------------------------
|
231
|
|
|
|
232
|
|
|
/**
|
233
|
|
|
* Text::setString
|
234
|
|
|
*
|
235
|
|
|
* @param $string
|
236
|
|
|
*
|
237
|
|
|
* @return static
|
238
|
|
|
*/
|
239
|
|
|
public function setString($string)
|
240
|
|
|
{
|
241
|
|
|
$this->string = trim($string);
|
242
|
|
|
|
243
|
|
|
return $this;
|
244
|
|
|
}
|
245
|
|
|
|
246
|
|
|
// ------------------------------------------------------------------------
|
247
|
|
|
|
248
|
|
|
/**
|
249
|
|
|
* Text::getAngle
|
250
|
|
|
*
|
251
|
|
|
* Gets text angle.
|
252
|
|
|
*
|
253
|
|
|
* @return int
|
254
|
|
|
*/
|
255
|
|
|
public function getAngle()
|
256
|
|
|
{
|
257
|
|
|
return $this->angle;
|
258
|
|
|
}
|
259
|
|
|
} |