3 namespace Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick;
6 * Defines imagemagick Convert operation.
8 * @ImageToolkitOperation(
9 * id = "imagemagick_convert",
10 * toolkit = "imagemagick",
11 * operation = "convert",
12 * label = @Translation("Convert"),
13 * description = @Translation("Instructs the toolkit to save the image with a specified format.")
16 class Convert extends ImagemagickImageToolkitOperationBase {
21 protected function arguments() {
24 'description' => 'The new extension of the converted image',
32 protected function validateArguments(array $arguments) {
33 if (!in_array($arguments['extension'], $this->getToolkit()->getSupportedExtensions())) {
34 throw new \InvalidArgumentException("Invalid extension ({$arguments['extension']}) specified for the image 'convert' operation");
42 protected function execute(array $arguments) {
43 // When source image is multi-frame, convert only the first frame.
44 if ($this->getToolkit()->getFrames()) {
45 $path = $this->getToolkit()->getSourceLocalPath();
46 if (strripos($path, '[0]', -3) === FALSE) {
47 $this->getToolkit()->setSourceLocalPath($path . '[0]');
52 ->setDestinationFormatFromExtension($arguments['extension']);