1 | <?php |
||
13 | class Border extends BaseManipulator |
||
14 | { |
||
15 | /** |
||
16 | * Perform border image manipulation. |
||
17 | * @param Image $image The source image. |
||
18 | * @return Image The manipulated image. |
||
19 | */ |
||
20 | 9 | public function run(Image $image) |
|
21 | { |
||
22 | 9 | if ($border = $this->getBorder($image)) { |
|
23 | 9 | list($width, $color, $method) = $border; |
|
24 | |||
25 | 9 | if ($method === 'overlay') { |
|
26 | 3 | return $this->runOverlay($image, $width, $color); |
|
27 | } |
||
28 | |||
29 | 6 | if ($method === 'shrink') { |
|
30 | 3 | return $this->runShrink($image, $width, $color); |
|
31 | } |
||
32 | |||
33 | 3 | if ($method === 'expand') { |
|
34 | 3 | return $this->runExpand($image, $width, $color); |
|
35 | } |
||
36 | } |
||
37 | |||
38 | return $image; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Resolve border amount. |
||
43 | * @param Image $image The source image. |
||
44 | * @return string The resolved border amount. |
||
45 | */ |
||
46 | 12 | public function getBorder(Image $image) |
|
62 | |||
63 | /** |
||
64 | * Get border width. |
||
65 | * @param Image $image The source image. |
||
66 | * @param double $dpr The device pixel ratio. |
||
67 | * @param string $width The border width. |
||
68 | * @return double The resolved border width. |
||
69 | */ |
||
70 | 15 | public function getWidth(Image $image, $dpr, $width) |
|
74 | |||
75 | /** |
||
76 | * Get formatted color. |
||
77 | * @param string $color The color. |
||
78 | * @return string The formatted color. |
||
79 | */ |
||
80 | 15 | public function getColor($color) |
|
84 | |||
85 | /** |
||
86 | * Resolve the border method. |
||
87 | * @param string $method The raw border method. |
||
88 | * @return string The resolved border method. |
||
89 | */ |
||
90 | 15 | public function getMethod($method) |
|
98 | |||
99 | /** |
||
100 | * Resolve the device pixel ratio. |
||
101 | * @return double The device pixel ratio. |
||
102 | */ |
||
103 | 15 | public function getDpr() |
|
115 | |||
116 | /** |
||
117 | * Run the overlay border method. |
||
118 | * @param Image $image The source image. |
||
119 | * @param double $width The border width. |
||
120 | * @param string $color The border color. |
||
121 | * @return Image The manipulated image. |
||
122 | */ |
||
123 | 3 | public function runOverlay(Image $image, $width, $color) |
|
135 | |||
136 | /** |
||
137 | * Run the shrink border method. |
||
138 | * @param Image $image The source image. |
||
139 | * @param double $width The border width. |
||
140 | * @param string $color The border color. |
||
141 | * @return Image The manipulated image. |
||
142 | */ |
||
143 | 3 | public function runShrink(Image $image, $width, $color) |
|
158 | |||
159 | /** |
||
160 | * Run the expand border method. |
||
161 | * @param Image $image The source image. |
||
162 | * @param double $width The border width. |
||
163 | * @param string $color The border color. |
||
164 | * @return Image The manipulated image. |
||
165 | */ |
||
166 | 3 | public function runExpand(Image $image, $width, $color) |
|
176 | } |
||
177 |