1 | <?php |
||
2 | |||
3 | namespace WagnerMontanini\GoomerApi\Support; |
||
4 | |||
5 | use CoffeeCode\Cropper\Cropper; |
||
6 | |||
7 | /** |
||
8 | * Class Thumb |
||
9 | * |
||
10 | * @author Wagner Montanini |
||
11 | * @package WagnerMontanini\GoomerApi\Support |
||
12 | */ |
||
13 | class Thumb |
||
14 | { |
||
15 | /** @var Cropper */ |
||
16 | private $cropper; |
||
17 | |||
18 | /** @var string */ |
||
19 | private $uploads; |
||
20 | |||
21 | /** |
||
22 | * Thumb constructor. |
||
23 | */ |
||
24 | public function __construct() |
||
25 | { |
||
26 | $this->cropper = new Cropper(CONF_IMAGE_CACHE, CONF_IMAGE_QUALITY['jpg'], CONF_IMAGE_QUALITY['png']); |
||
27 | $this->uploads = CONF_UPLOAD_DIR; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @param string $image |
||
32 | * @param int $width |
||
33 | * @param int|null $height |
||
34 | * @return string |
||
35 | */ |
||
36 | public function make(string $image, int $width, ?int $height = null): string |
||
37 | { |
||
38 | return $this->cropper->make("{$this->uploads}/{$image}", $width, $height); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param string|null $image |
||
43 | */ |
||
44 | public function flush(?string $image = null): void |
||
45 | { |
||
46 | if ($image) { |
||
47 | $this->cropper->flush("{$this->uploads}/{$image}"); |
||
48 | return; |
||
49 | } |
||
50 | |||
51 | $this->cropper->flush(); |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return Cropper |
||
57 | */ |
||
58 | public function cropper(): Cropper |
||
59 | { |
||
60 | return $this->cropper; |
||
61 | } |
||
62 | } |