PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / spatie / image-optimizer / src / OptimizerChainFactory.php

OptimizerChainFactory.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at vendor/spatie/image-optimizer/src/OptimizerChainFactory.php

89 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Spatie\ImageOptimizer;
4
5 use Spatie\ImageOptimizer\Optimizers\Avifenc;
6 use Spatie\ImageOptimizer\Optimizers\Cwebp;
7 use Spatie\ImageOptimizer\Optimizers\Gifsicle;
8 use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
9 use Spatie\ImageOptimizer\Optimizers\Optipng;
10 use Spatie\ImageOptimizer\Optimizers\Pngquant;
11 use Spatie\ImageOptimizer\Optimizers\Svgo;
12
13 class OptimizerChainFactory
14 {
15 public static function create(array $config = []): OptimizerChain
16 {
17 $optimizers = self::getOptimizers($config);
18 $optimizerChain = new OptimizerChain();
19
20 foreach ($optimizers as $optimizer => $optimizerConfig) {
21 $optimizerChain->addOptimizer(new $optimizer($optimizerConfig));
22 }
23
24 return $optimizerChain;
25 }
26
27 /**
28 * @return array<class-string, array>
29 */
30 private static function getOptimizers(array $config): array
31 {
32 if (self::configHasOptimizer($config)) {
33 return $config;
34 }
35
36 return [
37 Jpegoptim::class => [
38 '-m' . ($config['quality'] ?? 85),
39 '--force',
40 '--strip-all',
41 '--all-progressive',
42 ],
43 Pngquant::class => [
44 '--quality=' . ($config['quality'] ?? 85),
45 '--force',
46 ],
47 Optipng::class => [
48 '-i0',
49 '-o2',
50 '-quiet',
51 ],
52 Svgo::class => [],
53 Gifsicle::class => [
54 '-b',
55 '-O3',
56 ],
57 Cwebp::class => [
58 '-m 6',
59 '-pass 10',
60 '-mt',
61 '-q ' . ($config['quality'] ?? 90),
62 ],
63 Avifenc::class => [
64 '-a cq-level=' . (isset($config['quality']) ? round(63 - $config['quality'] * 0.63) : 23),
65 '-j all',
66 '--min 0',
67 '--max 63',
68 '--minalpha 0',
69 '--maxalpha 63',
70 '-a end-usage=q',
71 '-a tune=ssim',
72 ],
73 ];
74 }
75
76 private static function configHasOptimizer(array $config): bool
77 {
78 return (bool)array_intersect_key($config, [
79 Jpegoptim::class => null,
80 Pngquant::class => null,
81 Optipng::class => null,
82 Svgo::class => null,
83 Gifsicle::class => null,
84 Cwebp::class => null,
85 Avifenc::class => null,
86 ]);
87 }
88 }
89