40 $globalSettings = static::getGlobalSettings();
41 foreach ($optionNames as $optionName)
43 $setter =
'set' . ucfirst($optionName);
44 if (array_key_exists($optionName, $options))
46 $optionValue = $options[$optionName];
47 $this->$setter($optionValue);
49 else if (array_key_exists($optionName, $globalSettings))
51 $optionValue = $globalSettings[$optionName];
52 if (is_string($optionValue) && preg_match(
'/FileSize/i', $optionName))
57 $this->$setter($optionValue);
61 if (isset($options[
'ignoreUnknownImageTypes']) && is_bool($options[
'ignoreUnknownImageTypes']))
66 if (isset($options[
'treatOversizeImageAsFile']) && is_bool($options[
'treatOversizeImageAsFile']))
75 $configuration = \Bitrix\Main\Config\Configuration::getValue(
'ui');
76 if (isset($configuration[
'uploader'][
'settings']) && is_array($configuration[
'uploader'][
'settings']))
78 $settings = $configuration[
'uploader'][
'settings'];
91 if (!$fileData->isImage())
98 return !$result->isSuccess();
105 if (($fileData->
getWidth() === 0 || $fileData->
getHeight() === 0) && !$this->getIgnoreUnknownImageTypes())
107 return $result->addError(
new UploaderError(UploaderError::IMAGE_TYPE_NOT_SUPPORTED));
112 return $result->addError(
114 UploaderError::IMAGE_MAX_FILE_SIZE_EXCEEDED,
123 if ($fileData->
getSize() < $this->getImageMinFileSize())
125 return $result->addError(
127 UploaderError::IMAGE_MIN_FILE_SIZE_EXCEEDED,
136 if ($fileData->
getWidth() < $this->getImageMinWidth() || $fileData->
getHeight() < $this->getImageMinHeight())
138 return $result->addError(
140 UploaderError::IMAGE_IS_TOO_SMALL,
149 if ($fileData->
getWidth() > $this->getImageMaxWidth() || $fileData->
getHeight() > $this->getImageMaxHeight())
151 return $result->addError(
153 UploaderError::IMAGE_IS_TOO_BIG,
167 return $this->maxFileSize;
172 $this->maxFileSize = $maxFileSize;
179 return $this->minFileSize;
184 $this->minFileSize = $minFileSize;
191 return $this->acceptOnlyImages;
196 return $this->acceptedFileTypes;
201 $this->acceptedFileTypes = $acceptedFileTypes;
221 $imageExtensions = static::getImageExtensions();
230 $imageExtensions = explode(
',', \CFile::getImageExtensions());
232 return array_map(
function($extension) {
233 return '.' . ltrim($extension);
234 }, $imageExtensions);
239 return $this->ignoredFileNames;
244 $this->ignoredFileNames = [];
245 foreach ($fileNames as $fileName)
247 if (is_string($fileName) && mb_strlen($fileName) > 0)
249 $this->ignoredFileNames[] = mb_strtolower($fileName);
258 return $this->imageMinWidth;
263 $this->imageMinWidth = $imageMinWidth;
270 return $this->imageMinHeight;
275 $this->imageMinHeight = $imageMinHeight;
282 return $this->imageMaxWidth;
287 $this->imageMaxWidth = $imageMaxWidth;
294 return $this->imageMaxHeight;
299 $this->imageMaxHeight = $imageMaxHeight;
306 return $this->imageMaxFileSize;
311 $this->imageMaxFileSize = $imageMaxFileSize;
318 return $this->imageMinFileSize;
323 $this->imageMinFileSize = $imageMinFileSize;
330 return $this->ignoreUnknownImageTypes;
335 $this->ignoreUnknownImageTypes = $flag;
342 return $this->treatOversizeImageAsFile;
347 $this->treatOversizeImageAsFile = $flag;
static unformatInt(string $str)
setImageMinWidth(int $imageMinWidth)
validateImage(FileData $fileData)
setImageMaxHeight(int $imageMaxHeight)
__construct(array $options=[])
setAcceptOnlyImages(bool $flag=true)
setIgnoreUnknownImageTypes(bool $flag)
static getGlobalSettings()
bool $ignoreUnknownImageTypes
setAcceptedFileTypes(array $acceptedFileTypes)
setImageMaxFileSize(?int $imageMaxFileSize)
setIgnoredFileNames(array $fileNames)
bool $treatOversizeImageAsFile
setMinFileSize(int $minFileSize)
static getImageExtensions()
shouldTreatImageAsFile(FileData|array $fileData)
setImageMinFileSize(int $imageMinFileSize)
setImageMaxWidth(int $imageMaxWidth)
setMaxFileSize(?int $maxFileSize)
getIgnoreUnknownImageTypes()
setTreatOversizeImageAsFile(bool $flag)
setImageMinHeight(int $imageMinHeight)
shouldTreatOversizeImageAsFile()