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

Add support for the new quality options #473

Merged
merged 3 commits into from
Jan 31, 2015
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public function getConfigTreeBuilder()
->fixXmlConfig('filter', 'filters')
->children()
->scalarNode('quality')->defaultValue(100)->end()
->scalarNode('jpeg_quality')->defaultNull()->end()
->scalarNode('png_compression_level')->defaultNull()->end()
->scalarNode('png_compression_filter')->defaultNull()->end()
->scalarNode('format')->defaultNull()->end()
->booleanNode('animated')->defaultFalse()->end()
->scalarNode('cache')->defaultNull()->end()
Expand Down
10 changes: 10 additions & 0 deletions Imagine/Filter/FilterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ public function apply(BinaryInterface $binary, array $config)
'quality' => $config['quality']
);

if (isset($config['jpeg_quality'])) {
$options['jpeg_quality'] = $config['jpeg_quality'];
}
if (isset($config['png_compression_level'])) {
$options['png_compression_level'] = $config['png_compression_level'];
}
if (isset($config['png_compression_filter'])) {
$options['png_compression_filter'] = $config['png_compression_filter'];
}

if ($binary->getFormat() === 'gif' && $config['animated']) {
$options['animated'] = $config['animated'];
}
Expand Down
10 changes: 9 additions & 1 deletion Resources/doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ The default configuration for the bundle looks like this:
# Prototype
name:
quality: 100
jpeg_quality: ~
png_compression_level: ~
png_compression_filter: ~
animated: false
format: ~
cache: ~
Expand Down Expand Up @@ -67,7 +70,10 @@ Each filter set that you specify has the following options:
for more information) and options that should be passed to the specific filter type.
* ``post_processors`` - sets post-processors to be applied on filtered image
(see Post-Processors section in the :doc:`filters chapter <filters>` for details).
* ``quality`` - override the default quality of 100 for the generated images.
* ``quality`` - override the default quality of 100 for the generated images. **(deprecated)**
* ``jpeg_quality`` - override the quality for jpeg images (this overrides the ``quality`` option above)
* ``png_compression_level`` - set the compression level for png images (0-9) (this overrides the ``quality`` option above)
* ``png_compression_filter`` - set the compression filter for png images (see the ``filters`` parameter for ``imagepng`` function in `PHP manual`_ for more details)
* ``cache`` - override the default cache setting.
* ``data_loader`` - override the default data loader.
* ``route`` - optional list of route requirements, defaults and options using in
Expand All @@ -77,3 +83,5 @@ Each filter set that you specify has the following options:
is ignored).
* ``animated`` - support for resizing animated gif (currently not supported by
Imagine (PR pending))

.. _`PHP Manual`: http://php.net/imagepng
33 changes: 33 additions & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,39 @@ public function testShouldNotOverwriteDefaultResolverIfDefined()
$this->assertArrayHasKey('bar', $config['resolvers']['default']);
}

public function testNewFilterQualitySettings()
{
$config = $this->processConfiguration(
new Configuration(
array(
new BarResolverFactory,
new WebPathResolverFactory
),
array(
new FileSystemLoaderFactory
)
),
array(array(
'filter_sets' => array(
'test' => array(
'jpeg_quality' => 70,
'png_compression_level' => 9,
'png_compression_filter' => PNG_ALL_FILTERS,
),
)
))
);

$this->assertArrayHasKey('filter_sets', $config);
$this->assertArrayHasKey('test', $config['filter_sets']);
$this->assertArrayHasKey('jpeg_quality', $config['filter_sets']['test']);
$this->assertEquals(70, $config['filter_sets']['test']['jpeg_quality']);
$this->assertArrayHasKey('png_compression_level', $config['filter_sets']['test']);
$this->assertEquals(9, $config['filter_sets']['test']['png_compression_level']);
$this->assertArrayHasKey('png_compression_filter', $config['filter_sets']['test']);
$this->assertEquals(PNG_ALL_FILTERS, $config['filter_sets']['test']['png_compression_filter']);
}

/**
* @param ConfigurationInterface $configuration
* @param array $configs
Expand Down