Passed
Push — images-optim ( b62e9b )
by Arnaud
12:46 queued 09:01
created

Optimizer::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 23
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 30
ccs 10
cts 10
cp 1
crap 1
rs 9.552
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Cecil\Assets\Image;
15
16
use Spatie\ImageOptimizer\OptimizerChain;
17
use Spatie\ImageOptimizer\Optimizers\Cwebp;
18
use Spatie\ImageOptimizer\Optimizers\Gifsicle;
19
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
20
use Spatie\ImageOptimizer\Optimizers\Optipng;
21
use Spatie\ImageOptimizer\Optimizers\Pngquant;
22
use Spatie\ImageOptimizer\Optimizers\Svgo;
23
24
class Optimizer
25
{
26
    /**
27
     * Image Optimizer Chain.
28
     */
29 1
    public static function create(int $quality): OptimizerChain
30
    {
31 1
        return (new OptimizerChain())
32 1
            ->addOptimizer(new Jpegoptim([
33 1
                "--max=$quality",
34
                '--strip-all',
35
                '--all-progressive',
36
            ]))
37 1
            ->addOptimizer(new Pngquant([
38 1
                "--quality=$quality",
39
                '--force',
40
                '--skip-if-larger',
41
            ]))
42 1
            ->addOptimizer(new Optipng([
43
                '-i0',
44
                '-o2',
45
                '-quiet',
46
            ]))
47 1
            ->addOptimizer(new Svgo([
48
                '--disable={cleanupIDs,removeViewBox}',
49
            ]))
50 1
            ->addOptimizer(new Gifsicle([
51
                '-b',
52
                '-O3',
53
            ]))
54 1
            ->addOptimizer(new Cwebp([
55
                '-m 6',
56
                '-pass 10',
57
                '-mt',
58
                '-q $quality',
59
            ]));
60
    }
61
}
62