Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented ConfigurablePostProcessorInterface in OptiPngPostProcessor #764

Merged
merged 1 commit into from
Aug 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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