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

JpegOptimPostProcessor options #589

Closed
HitoTech opened this issue Apr 8, 2015 · 3 comments
Closed

JpegOptimPostProcessor options #589

HitoTech opened this issue Apr 8, 2015 · 3 comments

Comments

@HitoTech
Copy link

HitoTech commented Apr 8, 2015

When I use the JpegOptimPostProcessor in my project, it work just fine.

But when I'm trying to give a "max" option to the post-processor, it never takes it.

post_processors:
      jpegoptim: { max: 90 }

I see that the FilterManager call the process function of the post-processor, but the $postProcessorOptions never seems to be used.

Am I doing it the wrong way or should the FilterManager give option to the post-processor ?

@franmomu
Copy link
Contributor

Same here, based on JpegOptimPostProcessor code, something like this could be done to not modify the interface:

public function applyPostProcessors(BinaryInterface $binary, $config)
{
    $config += array('post_processors' => array());

    foreach ($config['post_processors'] as $postProcessorName => $postProcessorOptions) {
        if (!isset($this->postProcessors[$postProcessorName])) {
            throw new \InvalidArgumentException(sprintf(
                'Could not find post processor "%s"', $postProcessorName
            ));
        }

        $postProcessor = $this->postProcessors[$postProcessorName];

        $this->updatePostProcessorOptions($postProcessor, $postProcessorOptions);

        $binary = $postProcessor->process($binary);
    }

    return $binary;
}

private function updatePostProcessorOptions($postProcessor, $options)
{
    foreach ($options as $name => $value) {
        if (method_exists($postProcessor, $setter = 'set'.ucfirst($name))) {
            $postProcessor->$setter($value);
        }
    }
}

@franmomu
Copy link
Contributor

This can be closed as it's already possible: https://symfony.com/doc/current/bundles/LiipImagineBundle/post-processors/jpeg-optim.html

@michellesanver
Copy link
Contributor

Closing this based on @franmomu's comment above :) Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants