Update ImagickCLIDriver.php

configurable mogrify path, exceptions on exec() error
This commit is contained in:
Joby Elliott 2020-10-16 14:01:00 -06:00 committed by GitHub
parent ff7b5a0c6e
commit a92ab71dfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,11 +13,17 @@ use ByJoby\ImageTransform\Image;
*/ */
class ImagickCLIDriver extends AbstractCLIDriver 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 protected function mogrifyExecutable(): string
{ {
return static::MOGRIFY_EXECUTABLE; return $this->mogrify_executable;
} }
protected function doSave(Image $image, string $filename) protected function doSave(Image $image, string $filename)
@ -51,7 +57,10 @@ class ImagickCLIDriver extends AbstractCLIDriver
copy($image->source(), $tempFile); copy($image->source(), $tempFile);
// execute command and copy result // execute command and copy result
$command[] = '"' . $tempFile . '"'; $command[] = '"' . $tempFile . '"';
exec(implode(' ', $command)); exec(implode(' ', $command), $output, $return);
if ($return) {
throw new \Exception("Imagick CLI call failed, returned " . $return);
}
copy($tempFile, $filename); copy($tempFile, $filename);
} }
} }