|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UniSharp\LaravelFilemanager\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Intervention\Image\Facades\Image as InterventionImageV2; |
|
6
|
|
|
use Intervention\Image\Laravel\Facades\Image as InterventionImageV3; |
|
|
|
|
|
|
7
|
|
|
use UniSharp\LaravelFilemanager\Events\ImageIsCropping; |
|
8
|
|
|
use UniSharp\LaravelFilemanager\Events\ImageWasCropped; |
|
9
|
|
|
|
|
10
|
|
|
class CropController extends LfmController |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Show crop page. |
|
14
|
|
|
* |
|
15
|
|
|
* @return mixed |
|
16
|
|
|
*/ |
|
17
|
|
|
public function getCrop() |
|
18
|
|
|
{ |
|
19
|
|
|
return view('laravel-filemanager::crop') |
|
|
|
|
|
|
20
|
|
|
->with([ |
|
21
|
|
|
'working_dir' => request('working_dir'), |
|
|
|
|
|
|
22
|
|
|
'img' => $this->lfm->pretty(request('img')) |
|
|
|
|
|
|
23
|
|
|
]); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Crop the image (called via ajax). |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getCropImage($overWrite = true) |
|
30
|
|
|
{ |
|
31
|
|
|
$image_name = request('img'); |
|
|
|
|
|
|
32
|
|
|
$image_path = $this->lfm->setName($image_name)->path('absolute'); |
|
|
|
|
|
|
33
|
|
|
$crop_path = $image_path; |
|
34
|
|
|
|
|
35
|
|
|
if (! $overWrite) { |
|
36
|
|
|
$fileParts = explode('.', $image_name); |
|
37
|
|
|
$fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_cropped_' . time(); |
|
38
|
|
|
$crop_path = $this->lfm->setName(implode('.', $fileParts))->path('absolute'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
event(new ImageIsCropping($image_path)); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$crop_info = request()->only('dataWidth', 'dataHeight', 'dataX', 'dataY'); |
|
44
|
|
|
|
|
45
|
|
|
// crop image |
|
46
|
|
|
if (class_exists(InterventionImageV2::class)) { |
|
47
|
|
|
InterventionImageV2::make($image_path) |
|
48
|
|
|
->crop(...array_values($crop_info)) |
|
49
|
|
|
->save($crop_path); |
|
50
|
|
|
} else { |
|
51
|
|
|
InterventionImageV3::read($image_path) |
|
52
|
|
|
->crop(...array_values($crop_info)) |
|
53
|
|
|
->save($crop_path); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// make new thumbnail |
|
57
|
|
|
$this->lfm->generateThumbnail($image_name); |
|
58
|
|
|
|
|
59
|
|
|
event(new ImageWasCropped($image_path)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getNewCropImage() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->getCropimage(false); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths