-
Notifications
You must be signed in to change notification settings - Fork 728
/
Copy pathCropController.php
64 lines (50 loc) · 1.74 KB
/
CropController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
use Intervention\Image\Facades\Image;
use UniSharp\LaravelFilemanager\Events\ImageIsCropping;
use UniSharp\LaravelFilemanager\Events\ImageWasCropped;
class CropController extends LfmController
{
/**
* Show crop page.
*
* @return mixed
*/
public function getCrop()
{
return view('laravel-filemanager::crop')
->with([
'working_dir' => request('working_dir'),
'img' => $this->lfm->pretty(request('img'))
]);
}
/**
* Crop the image (called via ajax).
*/
public function getCropimage($overWrite = true)
{
$image_name = request('img');
$image_path = $this->lfm->setName($image_name)->path('absolute');
$crop_path = $image_path;
if (! $overWrite) {
$fileParts = explode('.', $image_name);
$fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_cropped_' . time();
$crop_path = $this->lfm->setName(implode('.', $fileParts))->path('absolute');
}
event(new ImageIsCropping($image_path));
$crop_info = request()->only('dataWidth', 'dataHeight', 'dataX', 'dataY');
// crop image
$name = $this->helper->getNameFromPath($image_path);
$imagefile = $this->lfm->pretty($image_path);
$image = Image::make($imagefile->get())
->crop(...array_values($crop_info));
$this->lfm->setName($name)->storage->put($image->stream());
// make new thumbnail
$this->lfm->generateThumbnail($image_name);
event(new ImageWasCropped($image_path));
}
public function getNewCropimage()
{
$this->getCropimage(false);
}
}