diff --git a/core/core.services.yml b/core/core.services.yml index 54dd634..7756fe6 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -527,6 +527,9 @@ services: image.toolkit.manager: class: Drupal\system\Plugin\ImageToolkitManager arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@config.factory'] + plugin.manager.image_toolkit_operation: + class: Drupal\system\Plugin\ImageToolkitOperationManager + arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] image.toolkit: class: Drupal\system\Plugin\ImageToolkitInterface factory_method: getDefaultToolkit diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index 858e2da..d54e291 100644 --- a/core/lib/Drupal/Core/Image/Image.php +++ b/core/lib/Drupal/Core/Image/Image.php @@ -325,7 +325,7 @@ public function crop($x, $y, $width, $height) { $width = (int) round($width); $height = (int) round($height); - return $this->getToolkit()->process('crop', $this, array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height)); + return $this->getToolkit()->apply('crop', $this, array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height)); } /** @@ -335,21 +335,21 @@ public function resize($width, $height) { $width = (int) round($width); $height = (int) round($height); - return $this->getToolkit()->process('resize', $this, array('width' => $width, 'height' => $height)); + return $this->getToolkit()->apply('resize', $this, array('width' => $width, 'height' => $height)); } /** * {@inheritdoc} */ public function desaturate() { - return $this->getToolkit()->process('desaturate', $this); + return $this->getToolkit()->apply('desaturate', $this); } /** * {@inheritdoc} */ public function rotate($degrees, $background = NULL) { - return $this->getToolkit()->process('rotate', $this, array('degrees' => $degrees, 'background' => $background)); + return $this->getToolkit()->apply('rotate', $this, array('degrees' => $degrees, 'background' => $background)); } /** diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php index 722ffc8..f9bca8b 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ResizeImageEffect.php @@ -38,20 +38,20 @@ public function applyEffect(ImageInterface $image) { /** * {@inheritdoc} */ - public function getSummary() { - return array( - '#theme' => 'image_resize_summary', - '#data' => $this->configuration, - ); + public function transformDimensions(array &$dimensions) { + // The new image will have the exact dimensions defined for the effect. + $dimensions['width'] = $this->configuration['width']; + $dimensions['height'] = $this->configuration['height']; } /** * {@inheritdoc} */ - public function transformDimensions(array &$dimensions) { - // The new image will have the exact dimensions defined for the effect. - $dimensions['width'] = $this->configuration['width']; - $dimensions['height'] = $this->configuration['height']; + public function getSummary() { + return array( + '#theme' => 'image_resize_summary', + '#data' => $this->configuration, + ); } /** diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php index 3a4bc5a..3b8f79e 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -22,7 +22,7 @@ * title = @Translation("GD2 image manipulation toolkit") * ) */ -class GDToolkit extends ImageToolkitBase implements ImageToolkitInterface { +class GDToolkit extends ImageToolkitBase { /** * {@inheritdoc} diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDCrop.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDCrop.php index e5e6592..9ed756f 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDCrop.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDCrop.php @@ -45,7 +45,7 @@ class GDCrop extends PluginBase implements ImageToolkitOperationInterface { * @return bool * TRUE if the operation was performed successfully, FALSE otherwise. */ - public function process(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { $res = $toolkit->createTmp($image, $data['width'], $data['height']); if (!imagecopyresampled($res, $image->getResource(), 0, 0, $data['x'], $data['y'], $data['width'], $data['height'], $data['width'], $data['height'])) { diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDDesaturate.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDDesaturate.php index b4c7c50..2628247 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDDesaturate.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDDesaturate.php @@ -41,7 +41,7 @@ class GDDesaturate extends PluginBase implements ImageToolkitOperationInterface * @return bool * TRUE if the operation was performed successfully, FALSE otherwise. */ - public function process(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { // PHP installations using non-bundled GD do not have imagefilter. if (!function_exists('imagefilter')) { watchdog('image', 'The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $image->getSource())); diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDResize.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDResize.php index fbe490d..4b5e332 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDResize.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDResize.php @@ -43,7 +43,7 @@ class GDResize extends PluginBase implements ImageToolkitOperationInterface { * @return bool * TRUE if the operation was performed successfully, FALSE otherwise. */ - public function process(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { $res = $toolkit->createTmp($image, $data['width'], $data['height']); if (!imagecopyresampled($res, $image->getResource(), 0, 0, 0, 0, $data['width'], $data['height'], $image->getWidth(), $image->getHeight())) { diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDRotate.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDRotate.php index a6fe1d7..2518f73 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDRotate.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/Operation/GDRotate.php @@ -47,7 +47,7 @@ class GDRotate extends PluginBase implements ImageToolkitOperationInterface { * @return bool * TRUE if the operation was performed successfully, FALSE otherwise. */ - public function process(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { // Ensure background variable is set. $data['background'] = isset($data['background']) ? $data['background'] : NULL; diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitBase.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitBase.php index 76910fd..ef18aa8 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitBase.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitBase.php @@ -13,16 +13,16 @@ /** * Base class implementation of an image toolkit. */ -abstract class ImageToolkitBase extends PluginBase { +abstract class ImageToolkitBase extends PluginBase implements ImageToolkitInterface { /** * @inheritdoc */ - public function process($operation, ImageInterface $image, array $data = array()) { + public function apply($operation, ImageInterface $image, array $data = array()) { $manager = \Drupal::service('image.toolkit.operation.manager'); $plugin_id = $manager->getToolkitOperationPluginId($this->getPluginId(), $operation); $plugin = $manager->createInstance($plugin_id); - return $plugin->process($this, $image, $data); + return $plugin->apply($this, $image, $data); } } diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php index 535f24f..d99f0ba 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php @@ -119,7 +119,7 @@ public static function isAvailable(); public static function supportedTypes(); /** - * Processes a toolkit operation. + * Applies a toolkit specific operation to an image. * * @param string $operation * The toolkit operation to be processed. @@ -131,5 +131,5 @@ public static function supportedTypes(); * @return mixed * TRUE if the operation was performed successfully, FALSE otherwise. */ - public function process($operation, ImageInterface $image, array $data = array()); + public function apply($operation, ImageInterface $image, array $data = array()); } diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitOperationInterface.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitOperationInterface.php index ae276bc..82001c8 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitOperationInterface.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitOperationInterface.php @@ -20,7 +20,7 @@ interface ImageToolkitOperationInterface extends PluginInspectionInterface { /** - * Processes an image toolkit operation. + * Applies a toolkit specific operation to an image. * * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit * An image toolkit. @@ -32,6 +32,6 @@ * @return bool * TRUE if the operation was performed successfully, FALSE otherwise. */ - public function process(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()); + public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()); } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestCrop.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestCrop.php index 194b84d..f51d876 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestCrop.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestCrop.php @@ -48,7 +48,7 @@ class TestCrop extends PluginBase implements ImageToolkitOperationInterface { * * @see image_crop() */ - public function process(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { $toolkit->logCall('crop', array($image, $data['x'], $data['y'], $data['width'], $data['height'])); return TRUE; } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestDesaturate.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestDesaturate.php index ca3630a..644bf79 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestDesaturate.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestDesaturate.php @@ -42,7 +42,7 @@ class TestDesaturate extends PluginBase implements ImageToolkitOperationInterfac * @return bool * TRUE or FALSE, based on success. */ - public function process(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { $toolkit->logCall('desaturate', array($image)); return TRUE; } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestResize.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestResize.php index e96003b..d583a4b 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestResize.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestResize.php @@ -44,7 +44,7 @@ class TestResize extends PluginBase implements ImageToolkitOperationInterface { * @return bool * TRUE or FALSE, based on success. */ - public function process(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { $toolkit->logCall('resize', array($image, $data['width'], $data['height'])); return TRUE; } diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestRotate.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestRotate.php index 8514ca8..be75fe5 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestRotate.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/Operation/TestRotate.php @@ -48,7 +48,7 @@ class TestRotate extends PluginBase implements ImageToolkitOperationInterface { * @return bool * TRUE or FALSE, based on success. */ - public function process(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { + public function apply(ImageToolkitInterface $toolkit, ImageInterface $image, array $data = array()) { // Ensure background variable is set. $data['background'] = isset($data['background']) ? $data['background'] : NULL; $toolkit->logCall('rotate', array($image, $data['degrees'], $data['background']));