protected function SmartCropTrait::validateArguments in Image Effects 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/ImageToolkit/Operation/SmartCropTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\SmartCropTrait::validateArguments()
- 8 src/Plugin/ImageToolkit/Operation/SmartCropTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\SmartCropTrait::validateArguments()
File
- src/
Plugin/ ImageToolkit/ Operation/ SmartCropTrait.php, line 43
Class
- SmartCropTrait
- Base trait for Smart Crop operations.
Namespace
Drupal\image_effects\Plugin\ImageToolkit\OperationCode
protected function validateArguments(array $arguments) {
// Assure integers for all arguments.
foreach ([
'width',
'height',
] as $key) {
$arguments[$key] = (int) round($arguments[$key]);
}
// Fail when width or height are 0 or negative.
if ($arguments['width'] <= 0) {
throw new \InvalidArgumentException("Invalid width ('{$arguments['width']}') specified for the image '{$this->getPluginDefinition()['operation']}' operation");
}
if ($arguments['height'] <= 0) {
throw new \InvalidArgumentException("Invalid height ('{$arguments['height']}') specified for the image '{$this->getPluginDefinition()['operation']}' operation");
}
switch ($arguments['algorithm']) {
case 'entropy_grid':
$arguments['algorithm_params'] = array_merge([
'grid_width' => 100,
'grid_height' => 100,
'grid_rows' => 5,
'grid_cols' => 5,
'grid_sub_rows' => 3,
'grid_sub_cols' => 3,
], $arguments['algorithm_params']);
break;
default:
break;
}
return $arguments;
}