Skip to content

Commit

Permalink
make JpegOptimPostProcessor Symfony4 compatible
Browse files Browse the repository at this point in the history
use Process instead of ProcessBuilder

https://github.com/symfony/symfony/blob/master/UPGRADE-4.0.md

The Symfony\Component\Process\ProcessBuilder class has been removed, use the Symfony\Component\Process\Process class directly instead.

I removed ProcessBuilder and use Process instead - this should have no sideeffects on existing 3.x installations - Process is also supported in those cases
  • Loading branch information
psytraxx committed Jan 1, 2018
1 parent 28a9248 commit 64d90d4
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -141,33 +141,32 @@ 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]);

$commandline = $this->jpegoptimBin;
$stripAll = array_key_exists('strip_all', $options) ? $options['strip_all'] : $this->stripAll;
if ($stripAll) {
$pb->add('--strip-all');
$commandline .= ' --strip-all';
}

$max = array_key_exists('max', $options) ? $options['max'] : $this->max;
if ($max) {
$pb->add('--max='.$max);
$commandline .= ' --max='.$max;
}

$progressive = array_key_exists('progressive', $options) ? $options['progressive'] : $this->progressive;
if ($progressive) {
$pb->add('--all-progressive');
$commandline .= ' --all-progressive';
} else {
$pb->add('--all-normal');
$commandline .= ' --all-normal';
}

$pb->add($input);
$commandline .= ' '.$input;
if ($binary instanceof FileBinaryInterface) {
copy($binary->getPath(), $input);
} else {
file_put_contents($input, $binary->getContent());
}

$proc = $pb->getProcess();
$proc = new Process($commandline);
$proc->run();

if (false !== strpos($proc->getOutput(), 'ERROR') || 0 !== $proc->getExitCode()) {
Expand Down

0 comments on commit 64d90d4

Please sign in to comment.