1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Watermark.php
См. документацию.
1<?php
8
9namespace Bitrix\Main\File\Image;
10
12{
13 const
14 ALIGN_LEFT = "left",
15 ALIGN_CENTER = "center",
16 ALIGN_RIGHT = "right",
17 ALIGN_TOP = "top",
18 ALIGN_BOTTOM = "bottom";
19
20 const
21 SIZE_SMALL = "small",
22 SIZE_MEDIUM = "medium",
23 SIZE_BIG = "big";
24
25 protected
26 $hAlign = self::ALIGN_RIGHT,
27 $vAlign = self::ALIGN_BOTTOM,
28 $size = self::SIZE_MEDIUM,
31
32 public function __construct()
33 {
34 }
35
41 public function setAlignment($hAlign, $vAlign)
42 {
43 $this->hAlign = $hAlign;
44 $this->vAlign = $vAlign;
45 return $this;
46 }
47
51 public function getRatio()
52 {
53 return $this->ratio;
54 }
55
61 public function alignPosition($width, $height, Rectangle $position)
62 {
64
65 if($this->vAlign == static::ALIGN_CENTER)
66 {
67 $position->setY(($height - $position->getHeight()) / 2);
68 }
69 elseif($this->vAlign == static::ALIGN_BOTTOM)
70 {
71 $position->setY($height - $position->getHeight() - $padding);
72 }
73 else //static::ALIGN_TOP
74 {
75 $position->setY($padding);
76 }
77
78 if($this->hAlign == static::ALIGN_CENTER)
79 {
80 $position->setX(($width - $position->getWidth()) / 2);
81 }
82 elseif($this->hAlign == static::ALIGN_RIGHT)
83 {
84 $position->setX(($width - $position->getWidth()) - $padding);
85 }
86 else //static::ALIGN_LEFT
87 {
88 $position->setX($padding);
89 }
90
91 if($position->getY() < $padding)
92 {
93 $position->setY($padding);
94 }
95 if($position->getX() < $padding)
96 {
97 $position->setX($padding);
98 }
99 }
100
105 public function setRatio($ratio)
106 {
107 $this->ratio = (float)$ratio;
108 return $this;
109 }
110
115 public function setSize($size)
116 {
117 $this->size = $size;
118 return $this;
119 }
120
124 public function getVerticalAlignment()
125 {
126 return $this->vAlign;
127 }
128
132 public function getHorizontalAlignment()
133 {
134 return $this->hAlign;
135 }
136
140 public function getPadding()
141 {
142 return $this->padding;
143 }
144
149 public function setPadding($padding)
150 {
151 $this->padding = (int)$padding;
152 return $this;
153 }
154
160 public static function createFromArray($params)
161 {
162 $params["position"] = strtolower(trim($params["position"] ?? ''));
163 $positions = ["topleft", "topcenter", "topright", "centerleft", "center", "centerright", "bottomleft", "bottomcenter", "bottomright"];
164 $shortPositions = ["tl", "tc", "tr", "ml", "mc", "mr", "bl", "bc", "br"];
165 $position = ['x' => 'right','y' => 'bottom']; // Default position
166
167 if(in_array($params["position"], $shortPositions))
168 {
169 $params["position"] = str_replace($shortPositions, $positions, $params["position"]);
170 }
171
172 if(in_array($params["position"], $positions))
173 {
174 foreach(['top', 'center', 'bottom'] as $k)
175 {
176 if(str_starts_with($params["position"], $k))
177 {
178 $position['y'] = $k;
179 $position['x'] = substr($params["position"], strlen($k));
180 if($position['x'] == '')
181 {
182 $position['x'] = ($k == 'center'? 'center' : 'right');
183 }
184 }
185 }
186 }
187
188 if(isset($params["type"]) && $params["type"] == "text")
189 {
190 $watermark = new TextWatermark(
191 $params['text'],
192 $params['font'],
194 );
195
196 if($params["text_width"] > 0)
197 {
198 $watermark->setWidth($params["text_width"]);
199 }
200 if($params["use_copyright"] == "Y")
201 {
202 $watermark->setCopyright(true);
203 }
204 }
205 else
206 {
207 $watermark = new ImageWatermark($params["file"] ?? null);
208
209 if(!isset($params["fill"]) || $params["fill"] <> 'repeat')
210 {
211 if(!isset($params["fill"]) || $params["fill"] <> 'exact')
212 {
213 if(isset($params["size"]) && $params["size"] == "real")
214 {
215 $params["fill"] = 'exact';
216 }
217 else
218 {
219 $params["fill"] = 'resize';
220 }
221 }
222 }
223 else
224 {
225 $position["x"] = "left";
226 $position["y"] = "top";
227 }
228
229 $watermark->setMode($params["fill"]);
230
231 if(isset($params["alpha_level"]))
232 {
233 $watermark->setAlpha(intval($params["alpha_level"]) / 100);
234 }
235 }
236
237 $watermark->setAlignment($position["x"], $position["y"]);
238
239 if(isset($params["padding"]))
240 {
241 $watermark->setPadding($params["padding"]);
242 }
243
244 if(isset($params["size"]))
245 {
246 $watermark->setSize($params["size"]);
247 }
248
249 if(isset($params["coefficient"]))
250 {
251 $watermark->setRatio($params["coefficient"]);
252 }
253
254 return $watermark;
255 }
256}
$positions
Определения access_edit.php:237
static createFromHex($color)
Определения Color.php:39
const SIZE_MEDIUM
Определения Watermark.php:22
const ALIGN_BOTTOM
Определения Watermark.php:18
static createFromArray($params)
Определения Watermark.php:160
alignPosition($width, $height, Rectangle $position)
Определения Watermark.php:61
setAlignment($hAlign, $vAlign)
Определения Watermark.php:41
const ALIGN_CENTER
Определения Watermark.php:15
const ALIGN_RIGHT
Определения Watermark.php:16
setRatio($ratio)
Определения Watermark.php:105
setPadding($padding)
Определения Watermark.php:149
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
font size
Определения invoice.php:442
$width
Определения html.php:68
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$k
Определения template_pdf.php:567