ImageFactory::getImageManager()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Conlect\ImageIIIF;
4
5
use Intervention\Image\ImageManager;
6
use Noodlehaus\Config;
7
use Noodlehaus\Parser\Json;
8
9
class ImageFactory
10
{
11
    /**
12
     * The image driver.
13
     *
14
     * @var string
15
     */
16
    protected string $driver = 'gd';
17
18
    protected array $config;
19
20
    public function __invoke(array $config = null)
21
    {
22
        if (is_null($config)) {
23
            $config = new Config(__DIR__ . '/../config');
24
        } else {
25
            $config = new Config(json_encode($config), new Json(), true);
26
        }
27
28
        $manager = $this->getImageManager($config['driver']);
29
30
        return new ImageIIIF($manager, $config);
31
    }
32
33
    /**
34
     *
35
     * @return ImageManager
36
     */
37
    public function getImageManager(string $driver = null)
38
    {
39
        if (is_null($driver)) {
40
            $driver = $this->driver;
41
        }
42
43
        return match ($driver) {
44
            'gd' => ImageManager::gd(),
45
            'imagick' => ImageManager::imagick(),
46
        };
47
    }
48
}
49