Passed
Branch language (ead312)
by Arnaud
05:02
created

Image::optimizer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

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