protected function ScaleAndSmartCropTrait::validateArguments in Image Effects 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/ImageToolkit/Operation/ScaleAndSmartCropTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\ScaleAndSmartCropTrait::validateArguments()
- 8 src/Plugin/ImageToolkit/Operation/ScaleAndSmartCropTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\ScaleAndSmartCropTrait::validateArguments()
File
- src/
Plugin/ ImageToolkit/ Operation/ ScaleAndSmartCropTrait.php, line 48
Class
- ScaleAndSmartCropTrait
- Base trait for Scale and Smart Crop operations.
Namespace
Drupal\image_effects\Plugin\ImageToolkit\OperationCode
protected function validateArguments(array $arguments) {
$actualWidth = $this
->getToolkit()
->getWidth();
$actualHeight = $this
->getToolkit()
->getHeight();
$scaleFactor = max($arguments['width'] / $actualWidth, $arguments['height'] / $actualHeight);
$arguments['resize'] = [
'width' => (int) round($actualWidth * $scaleFactor),
'height' => (int) round($actualHeight * $scaleFactor),
];
// 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");
}
return $arguments;
}