Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
resizedimage.php
1<?php
2
4
5
7
8class ResizedImage extends BFile
9{
10 protected $showInline = true;
11 protected $width;
12 protected $height;
13 protected $resizeType = BX_RESIZE_IMAGE_EXACT;
14 protected $filters;
15
16 public function __construct(array $file, $width, $height, $name = null)
17 {
18 parent::__construct($file, $name);
19
20 $this->setWidth($width);
21 $this->setHeight($height);
22 }
23
24 public static function createByImageId($imageId, $width, $height, $name = null)
25 {
26 $imageData = \CFile::getFileArray($imageId);
27 if (!$imageData)
28 {
29 throw new Main\ObjectNotFoundException("Could not find file");
30 }
31
32 return new self($imageData, $width, $height, $name);
33 }
34
35 public static function createByImageData(array $imageData, $width, $height, $name = null)
36 {
37 return new self($imageData, $width, $height, $name);
38 }
39
43 public function getWidth()
44 {
45 return $this->width;
46 }
47
53 public function setWidth($width)
54 {
55 $this->width = $width;
56
57 return $this;
58 }
59
63 public function getHeight()
64 {
65 return $this->height;
66 }
67
73 public function setHeight($height)
74 {
75 $this->height = $height;
76
77 return $this;
78 }
79
83 public function getResizeType()
84 {
85 return $this->resizeType;
86 }
87
93 public function setResizeType($resizeType)
94 {
95 $this->resizeType = $resizeType;
96
97 return $this;
98 }
99
103 public function getFilters()
104 {
105 return $this->filters;
106 }
107
113 public function setFilters($filters)
114 {
115 $this->filters = $filters;
116
117 return $this;
118 }
119
123 public function getImage()
124 {
125 return $this->file;
126 }
127
128 protected function prepareFile()
129 {
130 $file = parent::prepareFile();
131
132 $tmpFile = \CFile::resizeImageGet(
133 $file,
134 ['width' => $this->getWidth(), 'height' => $this->getHeight()],
135 $this->getResizeType(),
136 true,
137 $this->getFilters(),
138 true
139 );
140
141 $file['FILE_SIZE'] = $tmpFile['size'];
142 $file['SRC'] = $tmpFile['src'];
143
144 return $file;
145 }
146}
__construct(array $file, $width, $height, $name=null)
static createByImageId($imageId, $width, $height, $name=null)
static createByImageData(array $imageData, $width, $height, $name=null)