1 | <?php |
||
16 | class DimensionService extends AbstractService |
||
17 | { |
||
18 | /** |
||
19 | * Crop mode. Not necessary. |
||
20 | */ |
||
21 | const CROP_NONE = 0; |
||
22 | |||
23 | /** |
||
24 | * Crop in landscape. |
||
25 | */ |
||
26 | const CROP_LANDSCAPE = 1; |
||
27 | |||
28 | /** |
||
29 | * Crop in portrait. |
||
30 | */ |
||
31 | const CROP_PORTRAIT = 2; |
||
32 | |||
33 | /** |
||
34 | * Calc the ratio and check if the crop is landscape or portrait relevant. |
||
35 | * |
||
36 | * @param int $width |
||
37 | * @param int $height |
||
38 | * @param string $ratio In format "1:1" |
||
39 | * |
||
40 | * @return int |
||
41 | */ |
||
42 | public function getCropMode(int $width, int $height, string $ratio): int |
||
53 | |||
54 | /** |
||
55 | * Calc the focus width and height by the given ratio. |
||
56 | * |
||
57 | * @param int $width |
||
58 | * @param int $height |
||
59 | * @param string $ratio In format "1:1" |
||
60 | * |
||
61 | * @return array |
||
62 | */ |
||
63 | public function getFocusWidthAndHeight(int $width, int $height, string $ratio): array |
||
89 | |||
90 | /** |
||
91 | * Calculate the source X and Y position. |
||
92 | * |
||
93 | * @param int $cropMode |
||
94 | * @param int $width |
||
95 | * @param int $height |
||
96 | * @param int $focusWidth |
||
97 | * @param int $focusHeight |
||
98 | * @param int $focusPointX |
||
99 | * @param int $focusPointY |
||
100 | * |
||
101 | * @return array |
||
102 | */ |
||
103 | public function calculateSourcePosition( |
||
124 | |||
125 | /** |
||
126 | * get the shifted focus point point position |
||
127 | * for e.g. Frontend handling of the new created image. |
||
128 | * |
||
129 | * @param int $imgWidth |
||
130 | * @param int $imgHeight |
||
131 | * @param int $focusX |
||
132 | * @param int $focusY |
||
133 | * @param string $ratio |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | public function getShiftedFocusPointPosition(int $imgWidth, int $imgHeight, int $focusX, int $focusY, string $ratio): array |
||
170 | |||
171 | /** |
||
172 | * Check the ratio and create an array. |
||
173 | * |
||
174 | * @param string $ratio |
||
175 | * |
||
176 | * @throws \Exception |
||
177 | * |
||
178 | * @return array |
||
179 | */ |
||
180 | public function getRatio(string $ratio): array |
||
201 | |||
202 | /** |
||
203 | * Calc the shifted focus area. |
||
204 | * |
||
205 | * @param int $length |
||
206 | * @param int $focusLength |
||
207 | * @param int $focusPosition |
||
208 | * @param bool $invertScala |
||
209 | * |
||
210 | * @return array |
||
211 | */ |
||
212 | protected function getShiftedFocusAreaPosition(int $length, int $focusLength, int $focusPosition, bool $invertScala = false): array |
||
236 | |||
237 | /** |
||
238 | * Map the given ratio to the DB table. |
||
239 | * |
||
240 | * @param string $ratio |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | protected function mapDatabaseRatio(string $ratio): string |
||
253 | } |
||
254 |