diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index 4e5a2b2..ff33717 100644 --- a/core/lib/Drupal/Core/Image/Image.php +++ b/core/lib/Drupal/Core/Image/Image.php @@ -58,7 +58,7 @@ class Image implements ImageInterface { */ public function __construct(ImageToolkitInterface $toolkit, $source = NULL) { $this->toolkit = $toolkit; - $this->toolkit->setImage($this); + $this->getToolkit()->setImage($this); if ($source) { $this->source = $source; $this->parseFile(); @@ -76,14 +76,14 @@ public function isValid() { * {@inheritdoc} */ public function getHeight() { - return $this->toolkit->getHeight(); + return $this->getToolkit()->getHeight(); } /** * {@inheritdoc} */ public function getWidth() { - return $this->toolkit->getWidth(); + return $this->getToolkit()->getWidth(); } /** @@ -97,7 +97,7 @@ public function getFileSize() { * {@inheritdoc} */ public function getMimeType() { - return $this->toolkit->getMimeType(); + return $this->getToolkit()->getMimeType(); } /** @@ -111,7 +111,7 @@ public function getSource() { * {@inheritdoc} */ public function getToolkitId() { - return $this->toolkit->getPluginId(); + return $this->getToolkit()->getPluginId(); } /** @@ -131,7 +131,7 @@ public function save($destination = NULL) { } $destination = $destination ?: $this->getSource(); - if ($return = $this->toolkit->save($destination)) { + if ($return = $this->getToolkit()->save($destination)) { // Clear the cached file size and refresh the image information. clearstatcache(TRUE, $destination); $this->fileSize = filesize($destination); @@ -157,7 +157,7 @@ public function save($destination = NULL) { * image information is populated. */ protected function parseFile() { - if ($this->valid = $this->toolkit->parseFile()) { + if ($this->valid = $this->getToolkit()->parseFile()) { $this->fileSize = filesize($this->source); } return $this->valid; @@ -167,7 +167,7 @@ protected function parseFile() { * {@inheritdoc} */ public function apply($operation, array $arguments = array()) { - return $this->toolkit->apply($operation, $arguments); + return $this->getToolkit()->apply($operation, $arguments); } /** diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php index 79f9310..c2e6218 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php @@ -9,7 +9,6 @@ use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Utility\String; -use Drupal\Core\Image\ImageInterface; use Drupal\Core\Plugin\PluginBase; abstract class ImageToolkitOperationBase extends PluginBase implements ImageToolkitOperationInterface { @@ -136,30 +135,28 @@ protected function prepareArguments(array $arguments) { * This base implementation just returns the array of arguments and thus does * not need to be called by overriding methods. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. * @param array $arguments * An associative array of arguments to be used by the toolkit operation. * * @return array * The validated and corrected arguments array. * - * @throws \InvalidArgumentException. + * @throws \InvalidArgumentException * If one or more of the arguments are not valid. - * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException. + * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * If the plugin does not define a default for an optional argument. */ - protected function validateArguments(ImageInterface $image, array $arguments) { + protected function validateArguments(array $arguments) { return $arguments; } /** * {@inheritdoc} */ - public final function apply(ImageInterface $image, array $arguments) { + public final function apply(array $arguments) { $arguments = $this->prepareArguments($arguments); - $arguments = $this->validateArguments($image, $arguments); - return $this->execute($image, $arguments); + $arguments = $this->validateArguments($arguments); + return $this->execute($arguments); } /** @@ -170,14 +167,12 @@ protected function validateArguments(ImageInterface $image, array $arguments) { * When this method gets called, the implementer may assume all arguments, * also the optional ones, to be available, validated and corrected. * - * @param \Drupal\Core\Image\ImageInterface $image - * An image object. * @param array $arguments * An associative array of arguments to be used by the toolkit operation. * * @return bool * TRUE if the operation was performed successfully, FALSE otherwise. */ - abstract protected function execute(ImageInterface $image, array $arguments); + abstract protected function execute(array $arguments); } diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php index 482729a..8cd9da3 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationInterface.php @@ -27,7 +27,7 @@ * @return bool * TRUE if the operation was performed successfully, FALSE otherwise. * - * @throws \InvalidArgumentException. + * @throws \InvalidArgumentException * If one or more of the arguments are not valid. */ public function apply(array $arguments); diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index 4ff0d9f..c1a29a6 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -8,7 +8,6 @@ namespace Drupal\system\Plugin\ImageToolkit; use Drupal\Component\Utility\Unicode; -use Drupal\Core\Image\ImageInterface; use Drupal\Core\ImageToolkit\ImageToolkitBase; /** diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php index a01bd50..3219597 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Core\Image\ImageInterface; - /** * Defines GD2 Crop operation. * @@ -49,14 +47,14 @@ protected function arguments() { /** * {@inheritdoc} */ - protected function validateArguments(ImageInterface $image, array $arguments) { + protected function validateArguments(array $arguments) { // Assure at least one dimension. if (empty($arguments['width']) && empty($arguments['height'])) { throw new \InvalidArgumentException("At least one dimension ('width' or 'height') must be provided to the image 'crop' operation."); } // Preserve aspect. - $aspect = $this->getToolkit()->getHeight($image) / $this->getToolkit()->getWidth($image); + $aspect = $this->getToolkit()->getHeight() / $this->getToolkit()->getWidth(); $arguments['height'] = empty($arguments['height']) ? $arguments['width'] * $aspect : $arguments['height']; $arguments['width'] = empty($arguments['width']) ? $arguments['height'] / $aspect : $arguments['width']; @@ -79,7 +77,7 @@ protected function validateArguments(ImageInterface $image, array $arguments) { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments) { + protected function execute(array $arguments) { $res = $this->getToolkit()->createTmp($this->getToolkit()->getType(), $arguments['width'], $arguments['height']); if (!imagecopyresampled($res, $this->getToolkit()->getResource(), 0, 0, $arguments['x'], $arguments['y'], $arguments['width'], $arguments['height'], $arguments['width'], $arguments['height'])) { diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php index 069db6d..7eb83a2 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Core\Image\ImageInterface; - /** * Defines GD2 Desaturate operation. * @@ -33,10 +31,10 @@ protected function arguments() { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments) { + protected function execute(array $arguments) { // PHP installations using non-bundled GD do not have imagefilter. if (!function_exists('imagefilter')) { - \Drupal::logger('image')->notice('The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $image->getSource())); + \Drupal::logger('image')->notice('The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $this->getToolkit()->getImage()->getSource())); return FALSE; } diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php index ba92ecd..8ce057e 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Core\Image\ImageInterface; - /** * Defines GD2 resize operation. * @@ -39,7 +37,7 @@ protected function arguments() { /** * {@inheritdoc} */ - protected function validateArguments(ImageInterface $image, array $arguments) { + protected function validateArguments(array $arguments) { // Assure integers for all arguments. $arguments['width'] = (int) round($arguments['width']); $arguments['height'] = (int) round($arguments['height']); @@ -58,10 +56,10 @@ protected function validateArguments(ImageInterface $image, array $arguments) { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments = array()) { + protected function execute(array $arguments = array()) { $res = $this->getToolkit()->createTmp($this->getToolkit()->getType(), $arguments['width'], $arguments['height']); - if (!imagecopyresampled($res, $this->getToolkit()->getResource(), 0, 0, 0, 0, $arguments['width'], $arguments['height'], $this->getToolkit()->getWidth($image), $this->getToolkit()->getHeight($image))) { + if (!imagecopyresampled($res, $this->getToolkit()->getResource(), 0, 0, 0, 0, $arguments['width'], $arguments['height'], $this->getToolkit()->getWidth(), $this->getToolkit()->getHeight())) { return FALSE; } diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php index 11abeac..7191a62 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Core\Image\ImageInterface; - /** * Defines GD2 rotate operation. * @@ -41,10 +39,10 @@ protected function arguments() { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments) { + protected function execute(array $arguments) { // PHP installations using non-bundled GD do not have imagerotate. if (!function_exists('imagerotate')) { - \Drupal::logger('image')->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $image->getSource())); + \Drupal::logger('image')->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $this->getToolkit()->getImage()->getSource())); return FALSE; } diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php index 3d8b742..637f934 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Core\Image\ImageInterface; - /** * Defines GD2 Scale operation. * @@ -48,7 +46,7 @@ protected function arguments() { /** * {@inheritdoc} */ - protected function validateArguments(ImageInterface $image, array $arguments) { + protected function validateArguments(array $arguments) { // Assure at least one dimension. 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."); @@ -59,7 +57,7 @@ protected function validateArguments(ImageInterface $image, array $arguments) { // target dimensions is missing, that is the one that is calculated. If both // are specified then the dimension calculated is the one that would not be // calculated to be bigger than its target. - $aspect = $this->getToolkit()->getHeight($image) / $this->getToolkit()->getWidth($image); + $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); } @@ -85,12 +83,12 @@ protected function validateArguments(ImageInterface $image, array $arguments) { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments = array()) { + protected function execute(array $arguments = array()) { // Don't scale if we don't change the dimensions at all. - if ($arguments['width'] !== $this->getToolkit()->getWidth($image) || $arguments['height'] !== $this->getToolkit()->getHeight($image)) { + if ($arguments['width'] !== $this->getToolkit()->getWidth() || $arguments['height'] !== $this->getToolkit()->getHeight()) { // Don't upscale if the option isn't enabled. - if ($arguments['upscale'] || ($arguments['width'] <= $this->getToolkit()->getWidth($image) && $arguments['height'] <= $this->getToolkit()->getHeight($image))) { - return parent::execute($image, $arguments); + if ($arguments['upscale'] || ($arguments['width'] <= $this->getToolkit()->getWidth() && $arguments['height'] <= $this->getToolkit()->getHeight())) { + return parent::execute($arguments); } } return TRUE; diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php index 6b95e29..f9124a0 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Core\Image\ImageInterface; - /** * Defines GD2 Scale and crop operation. * @@ -39,9 +37,9 @@ protected function arguments() { /** * {@inheritdoc} */ - protected function validateArguments(ImageInterface $image, array $arguments) { - $actualWidth = $this->getToolkit()->getWidth($image); - $actualHeight = $this->getToolkit()->getHeight($image); + protected function validateArguments(array $arguments) { + $actualWidth = $this->getToolkit()->getWidth(); + $actualHeight = $this->getToolkit()->getHeight(); $scaleFactor = max($arguments['width'] / $actualWidth, $arguments['height'] / $actualHeight); @@ -58,9 +56,9 @@ protected function validateArguments(ImageInterface $image, array $arguments) { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments = array()) { - return $this->getToolkit()->apply('resize', $image, $arguments['resize']) - && $this->getToolkit()->apply('crop', $image, $arguments); + protected function execute(array $arguments = array()) { + return $this->getToolkit()->apply('resize', $arguments['resize']) + && $this->getToolkit()->apply('crop', $arguments); } }