1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
Watermark.php
См. документацию.
1
<?php
8
9
namespace
Bitrix\Main\File\Image;
10
11
class
Watermark
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,
29
$padding
= 0,
30
$ratio
;
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
{
63
$padding
=
$this->padding
;
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'
],
193
Color::createFromHex
(
$params
[
'color'
])
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
$positions
Определения
access_edit.php:237
Bitrix\Main\File\Image\Color\createFromHex
static createFromHex($color)
Определения
Color.php:39
Bitrix\Main\File\Image\ImageWatermark
Определения
ImageWatermark.php:12
Bitrix\Main\File\Image\Rectangle
Определения
Rectangle.php:14
Bitrix\Main\File\Image\Rectangle\setX
setX($x)
Определения
Rectangle.php:48
Bitrix\Main\File\Image\Rectangle\getX
getX()
Определения
Rectangle.php:39
Bitrix\Main\File\Image\Rectangle\setY
setY($y)
Определения
Rectangle.php:66
Bitrix\Main\File\Image\Rectangle\getHeight
getHeight()
Определения
Rectangle.php:93
Bitrix\Main\File\Image\Rectangle\getY
getY()
Определения
Rectangle.php:57
Bitrix\Main\File\Image\Rectangle\getWidth
getWidth()
Определения
Rectangle.php:75
Bitrix\Main\File\Image\TextWatermark
Определения
TextWatermark.php:14
Bitrix\Main\File\Image\Watermark
Определения
Watermark.php:12
Bitrix\Main\File\Image\Watermark\SIZE_MEDIUM
const SIZE_MEDIUM
Определения
Watermark.php:22
Bitrix\Main\File\Image\Watermark\__construct
__construct()
Определения
Watermark.php:32
Bitrix\Main\File\Image\Watermark\getPadding
getPadding()
Определения
Watermark.php:140
Bitrix\Main\File\Image\Watermark\getHorizontalAlignment
getHorizontalAlignment()
Определения
Watermark.php:132
Bitrix\Main\File\Image\Watermark\$ratio
$ratio
Определения
Watermark.php:30
Bitrix\Main\File\Image\Watermark\ALIGN_BOTTOM
const ALIGN_BOTTOM
Определения
Watermark.php:18
Bitrix\Main\File\Image\Watermark\$vAlign
$vAlign
Определения
Watermark.php:27
Bitrix\Main\File\Image\Watermark\createFromArray
static createFromArray($params)
Определения
Watermark.php:160
Bitrix\Main\File\Image\Watermark\alignPosition
alignPosition($width, $height, Rectangle $position)
Определения
Watermark.php:61
Bitrix\Main\File\Image\Watermark\getVerticalAlignment
getVerticalAlignment()
Определения
Watermark.php:124
Bitrix\Main\File\Image\Watermark\getRatio
getRatio()
Определения
Watermark.php:51
Bitrix\Main\File\Image\Watermark\ALIGN_TOP
const ALIGN_TOP
Определения
Watermark.php:17
Bitrix\Main\File\Image\Watermark\$padding
$padding
Определения
Watermark.php:29
Bitrix\Main\File\Image\Watermark\setAlignment
setAlignment($hAlign, $vAlign)
Определения
Watermark.php:41
Bitrix\Main\File\Image\Watermark\ALIGN_CENTER
const ALIGN_CENTER
Определения
Watermark.php:15
Bitrix\Main\File\Image\Watermark\ALIGN_RIGHT
const ALIGN_RIGHT
Определения
Watermark.php:16
Bitrix\Main\File\Image\Watermark\setSize
setSize($size)
Определения
Watermark.php:115
Bitrix\Main\File\Image\Watermark\setRatio
setRatio($ratio)
Определения
Watermark.php:105
Bitrix\Main\File\Image\Watermark\setPadding
setPadding($padding)
Определения
Watermark.php:149
Bitrix\Main\File\Image\Watermark\SIZE_SMALL
const SIZE_SMALL
Определения
Watermark.php:21
Bitrix\Main\File\Image\Watermark\$hAlign
$hAlign
Определения
Watermark.php:26
Bitrix\Main\File\Image\Watermark\ALIGN_LEFT
const ALIGN_LEFT
Определения
Watermark.php:14
Bitrix\Main\File\Image\Watermark\$size
$size
Определения
Watermark.php:28
Bitrix\Main\File\Image\Watermark\SIZE_BIG
const SIZE_BIG
Определения
Watermark.php:23
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
size
font size
Определения
invoice.php:442
$width
$width
Определения
html.php:68
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
$k
$k
Определения
template_pdf.php:567
bitrix
modules
main
lib
File
Image
Watermark.php
Создано системой
1.14.0