Resize.php in ImageMagick 8.3
File
src/Plugin/ImageToolkit/Operation/imagemagick/Resize.php
View source
<?php
namespace Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick;
class Resize extends ImagemagickImageToolkitOperationBase {
protected function arguments() {
return [
'width' => [
'description' => 'The new width of the resized image, in pixels',
],
'height' => [
'description' => 'The new height of the resized image, in pixels',
],
'filter' => [
'description' => 'An optional filter to apply for the resize',
'required' => FALSE,
'default' => '',
],
];
}
protected function validateArguments(array $arguments) {
$arguments['width'] = (int) round($arguments['width']);
$arguments['height'] = (int) round($arguments['height']);
if ($arguments['width'] <= 0) {
throw new \InvalidArgumentException("Invalid width ({$arguments['width']}) specified for the image 'resize' operation");
}
if ($arguments['height'] <= 0) {
throw new \InvalidArgumentException("Invalid height ({$arguments['height']}) specified for the image 'resize' operation");
}
return $arguments;
}
protected function execute(array $arguments = []) {
if (!empty($arguments['filter'])) {
$this
->addArgument('-filter ' . $arguments['filter']);
}
$this
->addArgument('-resize ' . $arguments['width'] . 'x' . $arguments['height'] . '!');
$this
->getToolkit()
->setWidth($arguments['width'])
->setHeight($arguments['height']);
return TRUE;
}
}
Classes
Name |
Description |
Resize |
Defines imagemagick resize operation. |