Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Gray | |
100.00% |
9 / 9 |
|
100.00% |
6 / 6 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setGray | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
getGray | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toCmyk | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toRgb | |
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 gray 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 Gray extends AbstractColor |
27 | { |
28 | |
29 | /** |
30 | * Gray |
31 | * @var float |
32 | */ |
33 | protected $gray = 0; |
34 | |
35 | /** |
36 | * Constructor |
37 | * |
38 | * Instantiate a PDF Gray Color object |
39 | * |
40 | * @param mixed $gray 0 - 100 |
41 | */ |
42 | public function __construct($gray) |
43 | { |
44 | $this->setGray($gray); |
45 | } |
46 | |
47 | /** |
48 | * Set the gray value |
49 | * |
50 | * @param mixed $gray |
51 | * @throws \OutOfRangeException |
52 | * @return Gray |
53 | */ |
54 | public function setGray($gray) |
55 | { |
56 | if (((int)$gray < 0) || ((int)$gray > 100)) { |
57 | throw new \OutOfRangeException('Error: The value must be between 0 and 100'); |
58 | } |
59 | $this->gray = (int)$gray; |
60 | return $this; |
61 | } |
62 | |
63 | /** |
64 | * Get the gray value |
65 | * |
66 | * @return float |
67 | */ |
68 | public function getGray() |
69 | { |
70 | return $this->gray; |
71 | } |
72 | |
73 | /** |
74 | * Convert to CMYK |
75 | * |
76 | * @return Cmyk |
77 | */ |
78 | public function toCmyk() |
79 | { |
80 | return new Cmyk(0, 0, 0, $this->gray); |
81 | } |
82 | |
83 | /** |
84 | * Convert to RGB |
85 | * |
86 | * @return Rgb |
87 | */ |
88 | public function toRgb() |
89 | { |
90 | return new Rgb($this->gray, $this->gray, $this->gray); |
91 | } |
92 | |
93 | /** |
94 | * Method to print the color object |
95 | * |
96 | * @return string |
97 | */ |
98 | public function __toString() |
99 | { |
100 | return (string)$this->gray; |
101 | } |
102 | |
103 | } |