Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
37 / 37 |
|
100.00% |
12 / 12 |
CRAP | |
100.00% |
1 / 1 |
Cmyk | |
100.00% |
37 / 37 |
|
100.00% |
12 / 12 |
20 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
setC | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
setM | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
setY | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
setK | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
getC | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getM | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getY | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getK | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toRgb | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
toGray | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Image\Color; |
15 | |
16 | /** |
17 | * Image CMYK color class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Image |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 3.4.0 |
25 | */ |
26 | class Cmyk extends AbstractColor |
27 | { |
28 | |
29 | /** |
30 | * Cyan |
31 | * @var float |
32 | */ |
33 | protected $c = 0; |
34 | |
35 | /** |
36 | * Magenta |
37 | * @var float |
38 | */ |
39 | protected $m = 0; |
40 | |
41 | /** |
42 | * Yellow |
43 | * @var float |
44 | */ |
45 | protected $y = 0; |
46 | |
47 | /** |
48 | * Black |
49 | * @var float |
50 | */ |
51 | protected $k = 0; |
52 | |
53 | /** |
54 | * Constructor |
55 | * |
56 | * Instantiate a PDF CMYK Color object |
57 | * |
58 | * @param mixed $c 0 - 100 |
59 | * @param mixed $m 0 - 100 |
60 | * @param mixed $y 0 - 100 |
61 | * @param mixed $k 0 - 100 |
62 | */ |
63 | public function __construct($c, $m, $y, $k) |
64 | { |
65 | $this->setC($c); |
66 | $this->setM($m); |
67 | $this->setY($y); |
68 | $this->setK($k); |
69 | } |
70 | |
71 | /** |
72 | * Set the cyan value |
73 | * |
74 | * @param mixed $c |
75 | * @throws \OutOfRangeException |
76 | * @return Cmyk |
77 | */ |
78 | public function setC($c) |
79 | { |
80 | if (((int)$c < 0) || ((int)$c > 100)) { |
81 | throw new \OutOfRangeException('Error: The value must be between 0 and 100'); |
82 | } |
83 | $this->c = (int)$c; |
84 | return $this; |
85 | } |
86 | |
87 | /** |
88 | * Set the magenta value |
89 | * |
90 | * @param mixed $m |
91 | * @throws \OutOfRangeException |
92 | * @return Cmyk |
93 | */ |
94 | public function setM($m) |
95 | { |
96 | if (((int)$m < 0) || ((int)$m > 100)) { |
97 | throw new \OutOfRangeException('Error: The value must be between 0 and 100'); |
98 | } |
99 | $this->m = (int)$m; |
100 | return $this; |
101 | } |
102 | |
103 | /** |
104 | * Set the yellow value |
105 | * |
106 | * @param mixed $y |
107 | * @throws \OutOfRangeException |
108 | * @return Cmyk |
109 | */ |
110 | public function setY($y) |
111 | { |
112 | if (((int)$y < 0) || ((int)$y > 100)) { |
113 | throw new \OutOfRangeException('Error: The value must be between 0 and 100'); |
114 | } |
115 | $this->y = (int)$y; |
116 | return $this; |
117 | } |
118 | |
119 | /** |
120 | * Set the black value |
121 | * |
122 | * @param mixed $k |
123 | * @throws \OutOfRangeException |
124 | * @return Cmyk |
125 | */ |
126 | public function setK($k) |
127 | { |
128 | if (((int)$k < 0) || ((int)$k > 100)) { |
129 | throw new \OutOfRangeException('Error: The value must be between 0 and 100'); |
130 | } |
131 | $this->k = (int)$k; |
132 | return $this; |
133 | } |
134 | |
135 | /** |
136 | * Get the cyan value |
137 | * |
138 | * @return float |
139 | */ |
140 | public function getC() |
141 | { |
142 | return $this->c; |
143 | } |
144 | |
145 | /** |
146 | * Get the magenta value |
147 | * |
148 | * @return float |
149 | */ |
150 | public function getM() |
151 | { |
152 | return $this->m; |
153 | } |
154 | |
155 | /** |
156 | * Get the yellow value |
157 | * |
158 | * @return float |
159 | */ |
160 | public function getY() |
161 | { |
162 | return $this->y; |
163 | } |
164 | |
165 | /** |
166 | * Get the black value |
167 | * |
168 | * @return float |
169 | */ |
170 | public function getK() |
171 | { |
172 | return $this->k; |
173 | } |
174 | |
175 | /** |
176 | * Convert to RGB |
177 | * |
178 | * @return Rgb |
179 | */ |
180 | public function toRgb() |
181 | { |
182 | // Calculate CMY. |
183 | $c = $this->c / 100; |
184 | $m = $this->m / 100; |
185 | $y = $this->y / 100; |
186 | $k = $this->k / 100; |
187 | |
188 | $cyan = (($c * (1 - $k)) + $k); |
189 | $magenta = (($m * (1 - $k)) + $k); |
190 | $yellow = (($y * (1 - $k)) + $k); |
191 | |
192 | // Calculate RGB. |
193 | $r = round((1 - $cyan) * 255); |
194 | $g = round((1 - $magenta) * 255); |
195 | $b = round((1 - $yellow) * 255); |
196 | |
197 | return new Rgb($r, $g, $b); |
198 | } |
199 | |
200 | /** |
201 | * Convert to Gray |
202 | * |
203 | * @return Gray |
204 | */ |
205 | public function toGray() |
206 | { |
207 | return new Gray($this->k); |
208 | } |
209 | |
210 | /** |
211 | * Method to print the color object |
212 | * |
213 | * @return string |
214 | */ |
215 | public function __toString() |
216 | { |
217 | return $this->c . ', ' . $this->m . ', ' . $this->y . ', ' . $this->k; |
218 | } |
219 | |
220 | } |