Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
33 / 33 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
Imagick | |
100.00% |
33 / 33 |
|
100.00% |
7 / 7 |
20 | |
100.00% |
1 / 1 |
hue | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
saturation | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
brightness | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
hsb | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
level | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
contrast | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
6 | |||
desaturate | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
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-2024 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\Adjust; |
15 | |
16 | /** |
17 | * Adjust class for Imagick |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Image |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 4.0.0 |
25 | */ |
26 | class Imagick extends AbstractAdjust |
27 | { |
28 | |
29 | /** |
30 | * Method to adjust the hue of the image. |
31 | * |
32 | * @param int $amount |
33 | * @return Imagick |
34 | */ |
35 | public function hue(int $amount): Imagick |
36 | { |
37 | if ($this->hasImage()) { |
38 | $this->image->getResource()->modulateImage(100, 100, $amount); |
39 | } |
40 | return $this; |
41 | } |
42 | |
43 | /** |
44 | * Method to adjust the saturation of the image. |
45 | * |
46 | * @param int $amount |
47 | * @return Imagick |
48 | */ |
49 | public function saturation(int $amount): Imagick |
50 | { |
51 | if ($this->hasImage()) { |
52 | $this->image->getResource()->modulateImage(100, $amount, 100); |
53 | } |
54 | return $this; |
55 | } |
56 | |
57 | /** |
58 | * Adjust the image brightness |
59 | * |
60 | * @param int $amount |
61 | * @return Imagick |
62 | */ |
63 | public function brightness(int $amount): Imagick |
64 | { |
65 | if ($this->hasImage()) { |
66 | $this->image->getResource()->modulateImage($amount, 100, 100); |
67 | } |
68 | return $this; |
69 | } |
70 | |
71 | /** |
72 | * Method to adjust the HSB of the image altogether. |
73 | * |
74 | * @param int $h |
75 | * @param int $s |
76 | * @param int $b |
77 | * @return Imagick |
78 | */ |
79 | public function hsb(int $h, int $s, int $b): Imagick |
80 | { |
81 | if ($this->hasImage()) { |
82 | $this->image->getResource()->modulateImage($h, $s, $b); |
83 | } |
84 | return $this; |
85 | } |
86 | |
87 | /** |
88 | * Method to adjust the levels of the image using a 0 - 255 range. |
89 | * |
90 | * @param int $black |
91 | * @param float $gamma |
92 | * @param int $white |
93 | * @return Imagick |
94 | */ |
95 | public function level(int $black, float $gamma, int $white): Imagick |
96 | { |
97 | if ($this->hasImage()) { |
98 | $quantumRange = $this->image->getResource()->getQuantumRange(); |
99 | |
100 | if ($black < 0) { |
101 | $black = 0; |
102 | } |
103 | if ($white > 255) { |
104 | $white = 255; |
105 | } |
106 | |
107 | $blackPoint = ($black / 255) * $quantumRange['quantumRangeLong']; |
108 | $whitePoint = ($white / 255) * $quantumRange['quantumRangeLong']; |
109 | |
110 | $this->image->getResource()->levelImage($blackPoint, $gamma, $whitePoint); |
111 | } |
112 | |
113 | return $this; |
114 | } |
115 | |
116 | /** |
117 | * Adjust the image contrast |
118 | * |
119 | * @param int $amount |
120 | * @return Imagick |
121 | */ |
122 | public function contrast(int $amount): Imagick |
123 | { |
124 | if ($this->hasImage()) { |
125 | if ($amount > 0) { |
126 | for ($i = 1; $i <= $amount; $i++) { |
127 | $this->image->getResource()->contrastImage(1); |
128 | } |
129 | } else if ($amount < 0) { |
130 | for ($i = -1; $i >= $amount; $i--) { |
131 | $this->image->getResource()->contrastImage(0); |
132 | } |
133 | } |
134 | } |
135 | return $this; |
136 | } |
137 | |
138 | /** |
139 | * Adjust the image desaturate |
140 | * |
141 | * @return Imagick |
142 | */ |
143 | public function desaturate(): Imagick |
144 | { |
145 | if ($this->hasImage()) { |
146 | $this->image->getResource()->modulateImage(100, 0, 100); |
147 | } |
148 | return $this; |
149 | } |
150 | |
151 | } |