1 | <?php |
||
7 | abstract class AbstractImage |
||
8 | { |
||
9 | protected $positions = [ |
||
10 | 'NORTHWEST' => ['x' => 0, 'y' => 0, 'padX' => 10, 'padY' => 10], |
||
11 | 'NORTH' => ['x' => 1, 'y' => 0, 'padX' => 0, 'padY' => 10], |
||
12 | 'NORTHEAST' => ['x' => 2, 'y' => 0, 'padX' => -10, 'padY' => 10], |
||
13 | 'WEST' => ['x' => 0, 'y' => 1, 'padX' => 10, 'padY' => 0], |
||
14 | 'CENTER' => ['x' => 1, 'y' => 1, 'padX' => 0, 'padY' => 0], |
||
15 | 'EAST' => ['x' => 2, 'y' => 1, 'padX' => -10, 'padY' => 0], |
||
16 | 'SOUTHWEST' => ['x' => 0, 'y' => 2, 'padX' => 10, 'padY' => -10], |
||
17 | 'SOUTH' => ['x' => 1, 'y' => 2, 'padX' => 0, 'padY' => -10], |
||
18 | 'SOUTHEAST' => ['x' => 2, 'y' => 2, 'padX' => -10, 'padY' => -10] |
||
19 | ]; |
||
20 | |||
21 | protected $image; |
||
22 | |||
23 | protected $width; |
||
24 | |||
25 | protected $height; |
||
26 | |||
27 | abstract protected function setSizes(): void; |
||
28 | |||
29 | abstract protected function resize(int $width, int $height): ImageInterface; |
||
30 | |||
31 | abstract protected function prepareWatermark(Image $watermark, int $x, int $y): ImageInterface; |
||
32 | |||
33 | abstract protected function tmp(string $source): ImageInterface; |
||
34 | |||
35 | abstract public function __toString(): string; |
||
36 | |||
37 | /** |
||
38 | * @param string $image |
||
39 | * @throws \Exception |
||
40 | */ |
||
41 | protected function init(string $image) |
||
57 | |||
58 | /** |
||
59 | * @param string $url |
||
60 | * @return \Exception|null |
||
61 | * @throws \Exception |
||
62 | */ |
||
63 | protected function getImageByURL(string $url): ?\Exception |
||
78 | |||
79 | /** |
||
80 | * @param string $base64 |
||
81 | * @throws \Exception |
||
82 | */ |
||
83 | protected function getImageByBase64(string $base64): void |
||
87 | |||
88 | protected function setImage($image): void |
||
92 | |||
93 | public function getImage() |
||
97 | |||
98 | public function getWidth(): int |
||
102 | |||
103 | protected function setWidth(int $width): void |
||
107 | |||
108 | public function getHeight(): int |
||
112 | |||
113 | protected function setHeight(int $height): void |
||
117 | |||
118 | /** |
||
119 | * @param int $height |
||
120 | * @return ImageInterface |
||
121 | */ |
||
122 | public function resizeByHeight(int $height): ImageInterface |
||
126 | |||
127 | /** |
||
128 | * @param int $width |
||
129 | * @return ImageInterface |
||
130 | */ |
||
131 | public function resizeByWidth(int $width): ImageInterface |
||
135 | |||
136 | /** |
||
137 | * @param int $percent |
||
138 | * @return ImageInterface |
||
139 | */ |
||
140 | public function resizeByPercent(int $percent): ImageInterface |
||
146 | |||
147 | /** |
||
148 | * @param string $mode |
||
149 | * @param int $param |
||
150 | * @return ImageInterface |
||
151 | * @throws \Exception |
||
152 | */ |
||
153 | public function resizeBy(string $mode, int $param): ImageInterface |
||
166 | |||
167 | /** |
||
168 | * @param Image $watermark |
||
169 | * @param string $position |
||
170 | * @return ImageInterface |
||
171 | * @throws \Exception |
||
172 | */ |
||
173 | public function watermark(Image $watermark, string $position): ImageInterface |
||
185 | |||
186 | public function getBase64(): string |
||
191 | } |
||
192 |