Skip to content

Commit

Permalink
Merge pull request #219 from 0xb4lint/fix-factory-quality
Browse files Browse the repository at this point in the history
Fix `quality` config parameter
  • Loading branch information
freekmurze authored May 16, 2024
2 parents 9d4ef03 + 68189ab commit d710967
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/OptimizerChainFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ private static function getOptimizers(array $config): array

private static function configHasOptimizer(array $config): bool
{
return (bool)array_diff_key($config, [
Jpegoptim::class,
Pngquant::class,
Optipng::class,
Svgo::class,
Gifsicle::class,
Cwebp::class,
Avifenc::class,
return (bool)array_intersect_key($config, [
Jpegoptim::class => null,
Pngquant::class => null,
Optipng::class => null,
Svgo::class => null,
Gifsicle::class => null,
Cwebp::class => null,
Avifenc::class => null,
]);
}
}
47 changes: 47 additions & 0 deletions tests/OptimizerChainFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,53 @@ function (Optimizer $optimizer) {
);
});

it('can use quality parameter with default config', function () {
$this->optimizerChain = OptimizerChainFactory::create(['quality' => 50])
->useLogger($this->log);

assertEquals(
[
new Jpegoptim([
'-m50',
'--force',
'--strip-all',
'--all-progressive',
]),
new Pngquant([
'--quality=50',
'--force',
]),
new Optipng([
'-i0',
'-o2',
'-quiet',
]),
new Svgo([]),
new Gifsicle([
'-b',
'-O3',
]),
new Cwebp([
'-m 6',
'-pass 10',
'-mt',
'-q 50',
]),
new Avifenc([
'-a cq-level=32',
'-j all',
'--min 0',
'--max 63',
'--minalpha 0',
'--maxalpha 63',
'-a end-usage=q',
'-a tune=ssim',
]),
],
$this->optimizerChain->getOptimizers()
);
});

it('can optimize a jpg', function () {
$tempFilePath = getTempFilePath('image.jpg');

Expand Down

0 comments on commit d710967

Please sign in to comment.