1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Image.php
См. документацию.
1<?php
8
10
12
13class Image
14{
15 const
16 FORMAT_PNG = \IMAGETYPE_PNG,
17 FORMAT_JPEG = \IMAGETYPE_JPEG,
18 FORMAT_GIF = \IMAGETYPE_GIF,
19 FORMAT_BMP = \IMAGETYPE_BMP,
20 FORMAT_WEBP = \IMAGETYPE_WEBP;
21
22 const
26
27 protected $file;
28
30 protected $engine;
31
36 public function __construct($file = null)
37 {
38 $this->file = $file;
39
40 $serviceLocator = DI\ServiceLocator::getInstance();
41 if($serviceLocator->has("main.imageEngine"))
42 {
43 $this->setEngine($serviceLocator->get("main.imageEngine"));
44 }
45 else
46 {
47 $this->setEngine(new Image\Gd());
48 }
49 }
50
55 public function setEngine(Image\Engine $engine)
56 {
57 $this->engine = $engine;
58
59 if($this->file !== null)
60 {
61 $this->engine->setFile($this->file);
62 }
63 }
64
69 public function getExifData()
70 {
71 return $this->engine->getExifData();
72 }
73
79 public function getInfo($flashEnabled = false)
80 {
81 return $this->engine->getInfo($flashEnabled);
82 }
83
88 public function load()
89 {
90 return $this->engine->load();
91 }
92
99 public function rotate($angle, Image\Color $bgColor = null)
100 {
101 if($bgColor === null)
102 {
103 $bgColor = new Image\Color();
104 }
105 return $this->engine->rotate($angle, $bgColor);
106 }
107
112 public function flipVertical()
113 {
114 return $this->engine->flipVertical();
115 }
116
121 public function flipHorizontal()
122 {
123 return $this->engine->flipHorizontal();
124 }
125
131 public function autoRotate($orientation)
132 {
133 if ($this->engine->substituted())
134 {
135 // no need to rotated a stub image
136 return false;
137 }
138
139 if($orientation > 1)
140 {
141 if($orientation == 7 || $orientation == 8)
142 {
143 $this->rotate(270);
144 }
145 elseif($orientation == 3 || $orientation == 4)
146 {
147 $this->rotate(180);
148 }
149 elseif($orientation == 5 || $orientation == 6)
150 {
151 $this->rotate(90);
152 }
153
154 if ($orientation == 2 || $orientation == 7 || $orientation == 4 || $orientation == 5)
155 {
156 $this->flipHorizontal();
157 }
158
159 $this->setOrientation(1);
160
161 return true;
162 }
163 return false;
164 }
165
171 public function setOrientation($orientation)
172 {
173 return $this->engine->setOrientation($orientation);
174 }
175
182 public function resize(Image\Rectangle $source, Image\Rectangle $destination)
183 {
184 return $this->engine->resize($source, $destination);
185 }
186
192 public function blur(int $sigma): bool
193 {
194 return $this->engine->blur($sigma);
195 }
196
202 public function filter(Image\Mask $mask)
203 {
204 return $this->engine->filter($mask);
205 }
206
212 public function drawWatermark(Image\Watermark $watermark)
213 {
214 if($watermark instanceof Image\TextWatermark)
215 {
216 return $this->engine->drawTextWatermark($watermark);
217 }
218 if($watermark instanceof Image\ImageWatermark)
219 {
220 return $this->engine->drawImageWatermark($watermark);
221 }
222 return false;
223 }
224
230 public function save($quality = 95)
231 {
232 if($quality <= 0 || $quality > 100)
233 {
234 $quality = 95;
235 }
236
237 if($this->engine->save($this->file, $quality))
238 {
239 $this->setFileAttributes($this->file);
240
241 return true;
242 }
243 return false;
244 }
245
253 public function saveAs($file, $quality = 95, $format = null)
254 {
255 if($quality <= 0 || $quality > 100)
256 {
257 $quality = 95;
258 }
259
260 if($this->engine->save($file, $quality, $format))
261 {
262 $this->setFileAttributes($file);
263
264 return true;
265 }
266 return false;
267 }
268
269 protected function setFileAttributes($file)
270 {
271 @chmod($file, BX_FILE_PERMISSIONS);
272 clearstatcache(true, $file);
273 }
274
279 public function getWidth()
280 {
281 return $this->engine->getWidth();
282 }
283
288 public function getHeight()
289 {
290 return $this->engine->getHeight();
291 }
292
297 public function getDimensions()
298 {
299 return $this->engine->getDimensions();
300 }
301
307 public function exceedsMaxSize(): bool
308 {
309 return $this->engine->exceedsMaxSize();
310 }
311
315 public function clear()
316 {
317 $this->engine->clear();
318 }
319}
static getInstance()
Определения servicelocator.php:33
blur(int $sigma)
Определения Image.php:192
autoRotate($orientation)
Определения Image.php:131
const FORMAT_JPEG
Определения Image.php:17
rotate($angle, Image\Color $bgColor=null)
Определения Image.php:99
const FORMAT_WEBP
Определения Image.php:20
const RESIZE_EXACT
Определения Image.php:25
load()
Определения Image.php:88
filter(Image\Mask $mask)
Определения Image.php:202
const FORMAT_GIF
Определения Image.php:18
const FORMAT_BMP
Определения Image.php:19
const FORMAT_PNG
Определения Image.php:16
getExifData()
Определения Image.php:69
__construct($file=null)
Определения Image.php:36
setEngine(Image\Engine $engine)
Определения Image.php:55
flipVertical()
Определения Image.php:112
const RESIZE_PROPORTIONAL
Определения Image.php:24
$engine
Определения Image.php:30
exceedsMaxSize()
Определения Image.php:307
drawWatermark(Image\Watermark $watermark)
Определения Image.php:212
$file
Определения Image.php:27
getInfo($flashEnabled=false)
Определения Image.php:79
getHeight()
Определения Image.php:288
clear()
Определения Image.php:315
saveAs($file, $quality=95, $format=null)
Определения Image.php:253
getDimensions()
Определения Image.php:297
resize(Image\Rectangle $source, Image\Rectangle $destination)
Определения Image.php:182
save($quality=95)
Определения Image.php:230
setOrientation($orientation)
Определения Image.php:171
const RESIZE_PROPORTIONAL_ALT
Определения Image.php:23
setFileAttributes($file)
Определения Image.php:269
getWidth()
Определения Image.php:279
flipHorizontal()
Определения Image.php:121
Определения action.php:3
Определения Color.php:9
Определения Image.php:9
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393