1 | <?php |
||
16 | class ImageTransformer |
||
17 | { |
||
18 | use Utils\BasePathTrait; |
||
19 | use Utils\CryptTrait; |
||
20 | |||
21 | protected $sizes; |
||
22 | |||
23 | /** |
||
24 | * Define the available sizes, for example: |
||
25 | * [ |
||
26 | * 'small' => 'resizeCrop,50,50', |
||
27 | * 'medium' => 'resize,500', |
||
28 | * 'big' => 'resize,1000', |
||
29 | * ]. |
||
30 | * |
||
31 | * @param array $sizes |
||
32 | * |
||
33 | * @return self |
||
34 | */ |
||
35 | public function sizes(array $sizes) |
||
41 | |||
42 | /** |
||
43 | * Execute the middleware. |
||
44 | * |
||
45 | * @param ServerRequestInterface $request |
||
46 | * @param ResponseInterface $response |
||
47 | * @param callable $next |
||
48 | * |
||
49 | * @return ResponseInterface |
||
50 | */ |
||
51 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
75 | |||
76 | /** |
||
77 | * Transform the image. |
||
78 | * |
||
79 | * @param ResponseInterface $response |
||
80 | * @param string $transform |
||
81 | * |
||
82 | * @return ResponseInterface |
||
83 | */ |
||
84 | private function transform(ResponseInterface $response, $transform) |
||
96 | |||
97 | /** |
||
98 | * Parses the path and return the file and transform values. |
||
99 | * For example, the path "/images/small.avatar.jpg" returns: |
||
100 | * ["/images/avatar.jpg", "resizeCrop,50,50"]. |
||
101 | * |
||
102 | * @param string $path |
||
103 | * |
||
104 | * @return null|array [file, transform] |
||
105 | */ |
||
106 | private function parsePath($path) |
||
132 | } |
||
133 |