AbstractImage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 59
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPalette() 0 21 4
A withPalette() 0 18 3
1
<?php
2
/**
3
 * This file is part of the Magickly project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Magickly\Image;
9
10
use GravityMedia\Magickly\Enum\ColorSpace;
11
use GravityMedia\Magickly\Image\Palette\PaletteInterface;
12
13
/**
14
 * Abstract image class.
15
 *
16
 * @package GravityMedia\Magickly\Image
17
 */
18
abstract class AbstractImage implements ImageInterface
19
{
20
    /**
21
     * @var array
22
     */
23
    protected static $supportedFormats = [
24
        'GIF',
25
        'JPEG',
26
        'PNG',
27
        'TIFF',
28
    ];
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getPalette()
34
    {
35
        switch ($this->getColorSpace()) {
36
            default:
37
                $palette = new Palette\RGB();
38
                break;
39
            case ColorSpace::COLOR_SPACE_CMYK:
40
                $palette = new Palette\CMYK();
41
                break;
42
            case ColorSpace::COLOR_SPACE_GRAYSCALE:
43
                $palette = new Palette\Grayscale();
44
                break;
45
        }
46
47
        $colorProfile = $this->getColorProfile();
48
        if (null !== $colorProfile) {
49
            $palette->setColorProfile($colorProfile);
50
        }
51
52
        return $palette;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function withPalette(PaletteInterface $palette)
59
    {
60
        $image = clone $this;
61
62
        if ($image->getColorSpace() === $palette->getColorSpace()) {
63
            return $image;
64
        }
65
66
        if (null === $image->getColorProfile()) {
67
            $image = $image->withColorProfile($image->getPalette()->getColorProfile());
68
        }
69
70
        $image = $image
71
            ->withColorProfile($palette->getColorProfile())
72
            ->withColorSpace($palette->getColorSpace());
73
74
        return $image;
75
    }
76
}
77