1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** @noinspection PhpTooManyParametersInspection */ |
4
|
|
|
|
5
|
|
|
declare(strict_types=1); |
6
|
|
|
|
7
|
|
|
namespace ReliqArts\GuidedImage\Concern; |
8
|
|
|
|
9
|
|
|
use Illuminate\Http\JsonResponse; |
10
|
|
|
use Illuminate\Http\Request; |
11
|
|
|
use Illuminate\Http\Response; |
12
|
|
|
use ReliqArts\GuidedImage\Contract\GuidedImage; |
13
|
|
|
use ReliqArts\GuidedImage\Contract\ImageDispenser; |
14
|
|
|
use ReliqArts\GuidedImage\Demand\Dummy; |
15
|
|
|
use ReliqArts\GuidedImage\Demand\Resize; |
16
|
|
|
use ReliqArts\GuidedImage\Demand\Thumbnail; |
17
|
|
|
use ReliqArts\GuidedImage\Result; |
18
|
|
|
|
19
|
|
|
trait Guide |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Empty skim cache. |
23
|
|
|
*/ |
24
|
|
|
public function emptyCache(ImageDispenser $imageDispenser): JsonResponse |
25
|
|
|
{ |
26
|
|
|
$errorMessage = 'Could not clear skim directories.'; |
27
|
|
|
|
28
|
|
|
if ($imageDispenser->emptyCache()) { |
29
|
|
|
return response()->json( |
30
|
|
|
new Result(true, '', ['Cache successfully cleared.']) |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return response()->json( |
35
|
|
|
new Result(false, $errorMessage, [$errorMessage]) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param mixed $width |
41
|
|
|
* @param mixed $height |
42
|
|
|
* @param mixed $aspect |
43
|
|
|
* @param mixed $upSize |
44
|
|
|
*/ |
45
|
|
|
public function resized( |
46
|
|
|
ImageDispenser $imageDispenser, |
47
|
|
|
Request $request, |
48
|
|
|
GuidedImage $guidedImage, |
49
|
|
|
$width, |
50
|
|
|
$height, |
51
|
|
|
$aspect = true, |
52
|
|
|
$upSize = false |
53
|
|
|
): Response { |
54
|
|
|
$demand = new Resize($request, $guidedImage, $width, $height, $aspect, $upSize); |
55
|
|
|
|
56
|
|
|
return $imageDispenser->getResizedImage($demand); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param mixed $method |
61
|
|
|
* @param mixed $width |
62
|
|
|
* @param mixed $height |
63
|
|
|
*/ |
64
|
|
|
public function thumb( |
65
|
|
|
ImageDispenser $imageDispenser, |
66
|
|
|
Request $request, |
67
|
|
|
GuidedImage $guidedImage, |
68
|
|
|
$method, |
69
|
|
|
$width, |
70
|
|
|
$height |
71
|
|
|
): Response { |
72
|
|
|
$demand = new Thumbnail($request, $guidedImage, $method, $width, $height); |
73
|
|
|
|
74
|
|
|
return $imageDispenser->getImageThumbnail($demand); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param mixed $width |
79
|
|
|
* @param mixed $height |
80
|
|
|
* @param mixed $color |
81
|
|
|
* @param mixed $fill |
82
|
|
|
*/ |
83
|
|
|
public function dummy( |
84
|
|
|
ImageDispenser $imageDispenser, |
85
|
|
|
$width, |
86
|
|
|
$height, |
87
|
|
|
$color = null, |
88
|
|
|
$fill = null |
89
|
|
|
): Response { |
90
|
|
|
$demand = new Dummy($width, $height, $color, $fill); |
91
|
|
|
|
92
|
|
|
return $imageDispenser->getDummyImage($demand); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|