From a92ab71dfdc5616b5de4ccce693400c0554e2d5c Mon Sep 17 00:00:00 2001 From: Joby Elliott Date: Fri, 16 Oct 2020 14:01:00 -0600 Subject: [PATCH] Update ImagickCLIDriver.php configurable mogrify path, exceptions on exec() error --- src/Drivers/ImagickCLIDriver.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Drivers/ImagickCLIDriver.php b/src/Drivers/ImagickCLIDriver.php index b6d82cd..08f9d30 100644 --- a/src/Drivers/ImagickCLIDriver.php +++ b/src/Drivers/ImagickCLIDriver.php @@ -13,11 +13,17 @@ use ByJoby\ImageTransform\Image; */ class ImagickCLIDriver extends AbstractCLIDriver { - const MOGRIFY_EXECUTABLE = 'magick mogrify'; + protected $mogrify_executable; + + public function __construct($mogrify_executable = 'magick mogrify') + { + parent::__construct(); + $this->mogrify_executable = $mogrify_executable; + } protected function mogrifyExecutable(): string { - return static::MOGRIFY_EXECUTABLE; + return $this->mogrify_executable; } protected function doSave(Image $image, string $filename) @@ -51,7 +57,10 @@ class ImagickCLIDriver extends AbstractCLIDriver copy($image->source(), $tempFile); // execute command and copy result $command[] = '"' . $tempFile . '"'; - exec(implode(' ', $command)); + exec(implode(' ', $command), $output, $return); + if ($return) { + throw new \Exception("Imagick CLI call failed, returned " . $return); + } copy($tempFile, $filename); } }