diff --git a/Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php b/Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php index a5190900a..7b001f618 100644 --- a/Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php +++ b/Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php @@ -15,7 +15,7 @@ use Liip\ImagineBundle\Binary\FileBinaryInterface; use Liip\ImagineBundle\Model\Binary; use Symfony\Component\Process\Exception\ProcessFailedException; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; class JpegOptimPostProcessor implements PostProcessorInterface, ConfigurablePostProcessorInterface { @@ -141,33 +141,33 @@ public function processWithConfiguration(BinaryInterface $binary, array $options throw new \RuntimeException(sprintf('Temp file can not be created in "%s".', $tempDir)); } - $pb = new ProcessBuilder([$this->jpegoptimBin]); + $processArguments = [$this->jpegoptimBin]; $stripAll = array_key_exists('strip_all', $options) ? $options['strip_all'] : $this->stripAll; if ($stripAll) { - $pb->add('--strip-all'); + $processArguments[] = '--strip-all'; } $max = array_key_exists('max', $options) ? $options['max'] : $this->max; if ($max) { - $pb->add('--max='.$max); + $processArguments[] = '--max='.$max; } $progressive = array_key_exists('progressive', $options) ? $options['progressive'] : $this->progressive; if ($progressive) { - $pb->add('--all-progressive'); + $processArguments[] = '--all-progressive'; } else { - $pb->add('--all-normal'); + $processArguments[] = '--all-normal'; } - $pb->add($input); + $processArguments[] = $input; if ($binary instanceof FileBinaryInterface) { copy($binary->getPath(), $input); } else { file_put_contents($input, $binary->getContent()); } - $proc = $pb->getProcess(); + $proc = new Process($processArguments); $proc->run(); if (false !== strpos($proc->getOutput(), 'ERROR') || 0 !== $proc->getExitCode()) { diff --git a/Imagine/Filter/PostProcessor/MozJpegPostProcessor.php b/Imagine/Filter/PostProcessor/MozJpegPostProcessor.php index 384cbab44..ff08321b7 100644 --- a/Imagine/Filter/PostProcessor/MozJpegPostProcessor.php +++ b/Imagine/Filter/PostProcessor/MozJpegPostProcessor.php @@ -14,7 +14,7 @@ use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Model\Binary; use Symfony\Component\Process\Exception\ProcessFailedException; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; /** * mozjpeg post-processor, for noticably better jpeg compression. @@ -85,24 +85,23 @@ public function processWithConfiguration(BinaryInterface $binary, array $options return $binary; } - $pb = new ProcessBuilder([$this->mozjpegBin]); + $processArguments = [$this->mozjpegBin]; // Places emphasis on DC - $pb->add('-quant-table'); - $pb->add(2); + $processArguments[] = '-quant-table'; + $processArguments[] = 2; $transformQuality = array_key_exists('quality', $options) ? $options['quality'] : $this->quality; if ($transformQuality !== null) { - $pb->add('-quality'); - $pb->add($transformQuality); + $processArguments[] = '-quality'; + $processArguments[] = $transformQuality; } - $pb->add('-optimise'); + $processArguments[] = '-optimise'; // Favor stdin/stdout so we don't waste time creating a new file. - $pb->setInput($binary->getContent()); - - $proc = $pb->getProcess(); + $proc = new Process($processArguments); + $proc->setInput($binary->getContent()); $proc->run(); if (false !== strpos($proc->getOutput(), 'ERROR') || 0 !== $proc->getExitCode()) { diff --git a/Imagine/Filter/PostProcessor/OptiPngPostProcessor.php b/Imagine/Filter/PostProcessor/OptiPngPostProcessor.php index 6a810dce9..07fd01f40 100644 --- a/Imagine/Filter/PostProcessor/OptiPngPostProcessor.php +++ b/Imagine/Filter/PostProcessor/OptiPngPostProcessor.php @@ -15,7 +15,7 @@ use Liip\ImagineBundle\Binary\FileBinaryInterface; use Liip\ImagineBundle\Model\Binary; use Symfony\Component\Process\Exception\ProcessFailedException; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; class OptiPngPostProcessor implements PostProcessorInterface, ConfigurablePostProcessorInterface { @@ -93,19 +93,19 @@ public function processWithConfiguration(BinaryInterface $binary, array $options throw new \RuntimeException(sprintf('Temp file can not be created in "%s".', $tempDir)); } - $pb = new ProcessBuilder([$this->optipngBin]); + $processArguments = [$this->optipngBin]; $level = array_key_exists('level', $options) ? $options['level'] : $this->level; if ($level !== null) { - $pb->add(sprintf('--o%d', $level)); + $processArguments[] = sprintf('--o%d', $level); } $stripAll = array_key_exists('strip_all', $options) ? $options['strip_all'] : $this->stripAll; if ($stripAll) { - $pb->add('--strip=all'); + $processArguments[] = '--strip=all'; } - $pb->add($input); + $processArguments[] = $input; if ($binary instanceof FileBinaryInterface) { copy($binary->getPath(), $input); @@ -113,7 +113,7 @@ public function processWithConfiguration(BinaryInterface $binary, array $options file_put_contents($input, $binary->getContent()); } - $proc = $pb->getProcess(); + $proc = new Process($processArguments); $proc->run(); if (false !== strpos($proc->getOutput(), 'ERROR') || 0 !== $proc->getExitCode()) { diff --git a/Imagine/Filter/PostProcessor/PngquantPostProcessor.php b/Imagine/Filter/PostProcessor/PngquantPostProcessor.php index 9dcd3f302..5c696e223 100644 --- a/Imagine/Filter/PostProcessor/PngquantPostProcessor.php +++ b/Imagine/Filter/PostProcessor/PngquantPostProcessor.php @@ -14,7 +14,7 @@ use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Model\Binary; use Symfony\Component\Process\Exception\ProcessFailedException; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; /** * pngquant post-processor, for optimal, web-safe, lossy png compression @@ -83,18 +83,17 @@ public function processWithConfiguration(BinaryInterface $binary, array $options return $binary; } - $pb = new ProcessBuilder([$this->pngquantBin]); + $processArguments = [$this->pngquantBin]; // Specify quality. $tranformQuality = array_key_exists('quality', $options) ? $options['quality'] : $this->quality; - $pb->add('--quality'); - $pb->add($tranformQuality); + $processArguments[] = '--quality'; + $processArguments[] = $tranformQuality; // Read to/from stdout to save resources. - $pb->add('-'); - $pb->setInput($binary->getContent()); - - $proc = $pb->getProcess(); + $processArguments[] = '-'; + $proc = new Process($processArguments); + $proc->setInput($binary->getContent()); $proc->run(); // 98 and 99 are "quality too low" to compress current current image which, while isn't ideal, is not a failure diff --git a/Tests/Fixtures/bash/empty-command.sh b/Tests/Fixtures/bash/empty-command.sh new file mode 100755 index 000000000..96b4b06ad --- /dev/null +++ b/Tests/Fixtures/bash/empty-command.sh @@ -0,0 +1 @@ +#!/bin/sh \ No newline at end of file diff --git a/Tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php b/Tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php new file mode 100644 index 000000000..2ec22788b --- /dev/null +++ b/Tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php @@ -0,0 +1,23 @@ +process($binary); + + $this->assertInstanceOf(BinaryInterface::class, $result); + } +} diff --git a/Tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php b/Tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php new file mode 100644 index 000000000..0df266539 --- /dev/null +++ b/Tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php @@ -0,0 +1,23 @@ +process($binary); + + $this->assertInstanceOf(BinaryInterface::class, $result); + } +} diff --git a/Tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php b/Tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php new file mode 100644 index 000000000..7e72965c4 --- /dev/null +++ b/Tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php @@ -0,0 +1,23 @@ +process($binary); + + $this->assertInstanceOf(BinaryInterface::class, $result); + } +} diff --git a/Tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php b/Tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php new file mode 100644 index 000000000..3d43ab115 --- /dev/null +++ b/Tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php @@ -0,0 +1,23 @@ +process($binary); + + $this->assertInstanceOf(BinaryInterface::class, $result); + } +}