Skip to content

Commit

Permalink
Merge pull request #764 from jehaby/feature-optipng-configurable
Browse files Browse the repository at this point in the history
Implemented ConfigurablePostProcessorInterface in OptiPngPostProcessor
  • Loading branch information
lsmith77 authored Aug 4, 2016
2 parents cc881be + 531b3b0 commit 3192820
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Imagine/Filter/PostProcessor/OptiPngPostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\ProcessBuilder;

class OptiPngPostProcessor implements PostProcessorInterface
class OptiPngPostProcessor implements PostProcessorInterface, ConfigurablePostProcessorInterface
{
/**
* @var string Path to optipng binary
Expand Down Expand Up @@ -49,10 +49,23 @@ public function __construct($optipngBin = '/usr/bin/optipng', $level = 7, $strip
* @throws ProcessFailedException
*
* @return BinaryInterface
*
* @see Implementation taken from Assetic\Filter\optipngFilter
*/
public function process(BinaryInterface $binary)
{
$this->processWithConfiguration($binary, array());
}

/**
* @param BinaryInterface $binary
* @param array $options
*
* @throws ProcessFailedException
*
* @return BinaryInterface|Binary
*
* @see Implementation taken from Assetic\Filter\optipngFilter
*/
public function processWithConfiguration(BinaryInterface $binary, array $options)
{
$type = strtolower($binary->getMimeType());
if (!in_array($type, array('image/png'))) {
Expand All @@ -65,11 +78,13 @@ public function process(BinaryInterface $binary)

$pb = new ProcessBuilder(array($this->optipngBin));

if ($this->level !== null) {
$pb->add(sprintf('--o%d', $this->level));
$level = array_key_exists('level', $options) ? $options['level'] : $this->level;
if ($level !== null) {
$pb->add(sprintf('--o%d', $level));
}

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

Expand Down

0 comments on commit 3192820

Please sign in to comment.