ImageWatermarkTemplate.php
6.0 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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
namespace Qcloud\Cos\ImageParamTemplate;
class ImageWatermarkTemplate extends ImageTemplate
{
private $image;
private $imageKey;
private $gravity;
private $dx;
private $dy;
private $blogo;
private $scatype;
private $spcent;
private $dissolve;
private $batch;
private $spacing;
private $degree;
public function __construct() {
parent::__construct();
$this->image = "";
$this->imageKey = "";
$this->gravity = "";
$this->dx = "";
$this->dy = "";
$this->blogo = "";
$this->scatype = "";
$this->spcent = "";
$this->dissolve = "";
$this->batch = "";
$this->spacing = "";
$this->degree = "";
}
/**
* 水印图片地址,需要经过 URL 安全的 Base64 编码。
* @param $value
*/
public function setImage($value) {
$this->image = "/image/" . $this->ciBase64($value);
}
/**
* 如果您在添加水印时不希望暴露水印所在的图片地址,可使用该参数。
* @param $value
*/
public function setImageKey($value) {
$this->imageKey = "/image_key/" . $this->ciBase64($value);
}
/**
* 图片水印位置,九宫格位置(参考九宫格方位图 ),默认值 SouthEast
* @param $value
*/
public function setGravity($value) {
$this->gravity = "/gravity/" . $value;
}
/**
* 水平(横轴)边距,单位为像素,缺省值为0
* @param $value
*/
public function setDx($value) {
$this->dx = "/dx/" . $value;
}
/**
* 垂直(纵轴)边距,单位为像素,默认值为0
* @param $value
*/
public function setDy($value) {
$this->dy = "/dy/" . $value;
}
/**
* 水印图适配功能,适用于水印图尺寸过大的场景(如水印墙)。共有两种类型:
* 当 blogo 设置为1时,水印图会被缩放至与原图相似大小后添加
* 当 blogo 设置为2时,水印图会被直接裁剪至与原图相似大小后添加
* @param $value
*/
public function setBlogo($value) {
$this->blogo = "/blogo/" . $value;
}
/**
* 根据原图的大小,缩放调整水印图的大小:
* 当 scatype 设置为1时,按原图的宽缩放
* 当 scatype 设置为2时,按原图的高缩放
* 当 scatype 设置为3时,按原图的整体面积缩放
* @param $value
*/
public function setScatype($value) {
$this->scatype = "/scatype/" . $value;
}
/**
* 与 scatype 搭配使用:
* 当 scatype 设置为1时,该有效值为[1,1000],单位为千分比
* 当 scatype 设置为2时,该有效值为[1,1000],单位为千分比
* 当 scatype 设置为3时,该有效值为[1,250],单位为千分比。
* @param $value
*/
public function setSpcent($value) {
$this->spcent = "/spcent/" . $value;
}
/**
* 图片水印的透明度,取值为1 - 100,默认90(90%不透明度)
* @param $value
*/
public function setDissolve($value) {
$this->dissolve = "/dissolve/" . $value;
}
/**
* 平铺水印功能,可将图片水印平铺至整张图片。值为1时,表示开启平铺水印功能
* @param $value
*/
public function setBatch($value) {
$this->batch = "/batch/" . $value;
}
/**
* 平铺水印功能,宽高百分比
* @param $value
*/
public function setSpacing($value) {
$this->spacing = "/spacing/" . $value;
}
/**
* 当 batch 值为1时生效。图片水印的旋转角度设置,取值范围为0 - 360,默认0
* @param $value
*/
public function setDegree($value) {
$this->degree = "/degree/" . $value;
}
public function getImage() {
return $this->image;
}
public function getImageKey() {
return $this->imageKey;
}
public function getGravity() {
return $this->gravity;
}
public function getDx() {
return $this->dx;
}
public function getDy() {
return $this->dy;
}
public function getBlogo() {
return $this->blogo;
}
public function getScatype() {
return $this->scatype;
}
public function getSpcent() {
return $this->spcent;
}
public function getDissolve() {
return $this->dissolve;
}
public function getBatch() {
return $this->batch;
}
public function getSpacing() {
return $this->spacing;
}
public function getDegree() {
return $this->degree;
}
public function queryString() {
$head = "watermark/1";
$res = "";
if($this->image) {
$res .= $this->image;
}
if($this->imageKey) {
$res .= $this->imageKey;
}
if($this->gravity) {
$res .= $this->gravity;
}
if($this->dx) {
$res .= $this->dx;
}
if($this->dy) {
$res .= $this->dy;
}
if($this->blogo) {
$res .= $this->blogo;
}
if($this->scatype) {
$res .= $this->scatype;
}
if($this->spcent) {
$res .= $this->spcent;
}
if($this->dissolve) {
$res .= $this->dissolve;
}
if($this->batch) {
$res .= $this->batch;
}
if($this->spacing) {
$res .= $this->spacing;
}
if($this->degree) {
$res .= $this->degree;
}
if($res) {
$res = $head . $res;
}
return $res;
}
public function resetRule() {
$this->image = "";
$this->imageKey = "";
$this->gravity = "";
$this->dx = "";
$this->dy = "";
$this->blogo = "";
$this->scatype = "";
$this->spcent = "";
$this->dissolve = "";
$this->batch = "";
$this->spacing = "";
$this->degree = "";
}
}