Scale.php in Imagick 8
File
src/Plugin/ImageToolkit/Operation/imagick/Scale.php
View source
<?php
namespace Drupal\imagick\Plugin\ImageToolkit\Operation\imagick;
class Scale extends Resize {
protected function validateArguments(array $arguments) {
if (empty($arguments['width']) && empty($arguments['height'])) {
throw new \InvalidArgumentException("At least one dimension ('width' or 'height') must be provided to the image 'scale' operation");
}
$aspect = $this
->getToolkit()
->getHeight() / $this
->getToolkit()
->getWidth();
if ($arguments['width'] && !$arguments['height'] || $arguments['width'] && $arguments['height'] && $aspect < $arguments['height'] / $arguments['width']) {
$arguments['height'] = (int) round($arguments['width'] * $aspect);
}
else {
$arguments['width'] = (int) round($arguments['height'] / $aspect);
}
$arguments['width'] = (int) round($arguments['width']);
$arguments['height'] = (int) round($arguments['height']);
if ($arguments['width'] <= 0) {
throw new \InvalidArgumentException($this
->t("Invalid width (@value) specified for the image 'scale' operation", [
'@value' => $arguments['width'],
]));
}
if ($arguments['height'] <= 0) {
throw new \InvalidArgumentException($this
->t("Invalid height (@value) specified for the image 'scale' operation", [
'@value' => $arguments['height'],
]));
}
return $arguments;
}
protected function execute(array $arguments = []) {
if ($arguments['width'] !== $this
->getToolkit()
->getWidth() || $arguments['height'] !== $this
->getToolkit()
->getHeight()) {
if ($arguments['upscale'] || $arguments['width'] <= $this
->getToolkit()
->getWidth() && $arguments['height'] <= $this
->getToolkit()
->getHeight()) {
return parent::execute($arguments);
}
}
return TRUE;
}
}
Classes
Name |
Description |
Scale |
Defines imagick scale operation. |