-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathColorspaceModifier.php
More file actions
59 lines (50 loc) · 1.75 KB
/
ColorspaceModifier.php
File metadata and controls
59 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Colors\Cmyk\Colorspace as Cmyk;
use Intervention\Image\Colors\Hsl\Colorspace as Hsl;
use Intervention\Image\Colors\Hsv\Colorspace as Hsv;
use Intervention\Image\Colors\Oklab\Colorspace as Oklab;
use Intervention\Image\Colors\Oklch\Colorspace as Oklch;
use Intervention\Image\Colors\Rgb\Colorspace as Rgb;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\ColorspaceInterface;
class ColorspaceModifier extends SpecializableModifier
{
public function __construct(public string|ColorspaceInterface $target)
{
//
}
/**
* Build target color space
*
* @throws NotSupportedException
*/
protected function targetColorspace(): ColorspaceInterface
{
if ($this->target instanceof ColorspaceInterface) {
return $this->target;
}
if (class_exists($this->target)) {
$colorspace = new $this->target();
if (!$colorspace instanceof ColorspaceInterface) {
throw new NotSupportedException(
'Target colorspace "' . $this->target . '" is not supported by driver',
);
}
return $colorspace;
}
return match (strtolower($this->target)) {
'rgb', 'srgb', 'rgba', 'srgba' => new Rgb(),
'cmyk' => new Cmyk(),
'hsl' => new Hsl(),
'hsv', 'hsb' => new Hsv(),
'oklab' => new Oklab(),
'oklch' => new Oklch(),
default => throw new NotSupportedException(
'Colorspace is not supported by driver',
),
};
}
}