diff --git a/core/lib/Drupal/Core/Image/ImageInterface.php b/core/lib/Drupal/Core/Image/ImageInterface.php index b8ca6a8..e0b6bda 100644 --- a/core/lib/Drupal/Core/Image/ImageInterface.php +++ b/core/lib/Drupal/Core/Image/ImageInterface.php @@ -149,13 +149,16 @@ public function scale($width, $height = NULL, $upscale = FALSE); public function scaleAndCrop($width, $height); /** - * Converts an image to a specified format. + * Instructs the toolkit to save the image in the specified format. * * @param string $format * The format to convert to (e.g. 'jpeg', 'png'). Allowed values depend on * the implementation of the convert operation of the image toolkit. For a * working example, see * \Drupal\system\Plugin\ImageToolkit\Operation\gd\Convert. + * + * @return bool + * TRUE on success, FALSE on failure. */ public function convert($format); diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php index 38dfff8..8ca9754 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php @@ -17,7 +17,7 @@ * toolkit = "gd", * operation = "convert", * label = @Translation("Convert"), - * description = @Translation("Converts an image to the given format.") + * description = @Translation("Instructs the toolkit to save the image in the specified format.") * ) */ class Convert extends GDImageToolkitOperationBase { @@ -47,22 +47,8 @@ protected function validateArguments(array $arguments) { * {@inheritdoc} */ protected function execute(array $arguments = array()) { - $type = FALSE; - switch ($arguments['format']) { - case 'jpeg': - case 'jpg': - case 'jpe': - $type = IMAGETYPE_JPEG; - break; - - default: - $constant = 'IMAGETYPE_' . \Drupal\Component\Utility\Unicode::strtoupper($arguments['format']); - if (defined($constant)) { - $type = constant($constant); - } - break; - } - + // Make sure we have an image type. + $type = $this->getToolkit()->getType(); if (!$type) { return FALSE; } @@ -74,9 +60,8 @@ protected function execute(array $arguments = array()) { imagedestroy($this->getToolkit()->getResource()); - $this->getToolkit()->setType($type); // Update image object. - $this->getToolkit()->setResource($res); + $this->getToolkit()->setType($type); return TRUE; }