|
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\ImageIsResizing; |
|
8
|
|
|
use UniSharp\LaravelFilemanager\Events\ImageWasResized; |
|
9
|
|
|
|
|
10
|
|
|
class ResizeController extends LfmController |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Dipsplay image for resizing. |
|
14
|
|
|
* |
|
15
|
|
|
* @return mixed |
|
16
|
|
|
*/ |
|
17
|
|
|
public function getResize() |
|
18
|
|
|
{ |
|
19
|
|
|
$ratio = 1.0; |
|
20
|
|
|
$image = request('img'); |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
if (class_exists(InterventionImageV2::class)) { |
|
23
|
|
|
$original_image = InterventionImageV2::make($this->lfm->setName($image)->path('absolute')); |
|
|
|
|
|
|
24
|
|
|
} else { |
|
25
|
|
|
$original_image = InterventionImageV3::read($this->lfm->setName($image)->path('absolute')); |
|
26
|
|
|
} |
|
27
|
|
|
$original_width = $original_image->width(); |
|
28
|
|
|
$original_height = $original_image->height(); |
|
29
|
|
|
|
|
30
|
|
|
$scaled = false; |
|
31
|
|
|
|
|
32
|
|
|
// FIXME size should be configurable |
|
33
|
|
|
if ($original_width > 600) { |
|
34
|
|
|
$ratio = 600 / $original_width; |
|
35
|
|
|
$width = $original_width * $ratio; |
|
36
|
|
|
$height = $original_height * $ratio; |
|
37
|
|
|
$scaled = true; |
|
38
|
|
|
} else { |
|
39
|
|
|
$width = $original_width; |
|
40
|
|
|
$height = $original_height; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if ($height > 400) { |
|
44
|
|
|
$ratio = 400 / $original_height; |
|
45
|
|
|
$width = $original_width * $ratio; |
|
46
|
|
|
$height = $original_height * $ratio; |
|
47
|
|
|
$scaled = true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return view('laravel-filemanager::resize') |
|
|
|
|
|
|
51
|
|
|
->with('img', $this->lfm->pretty($image)) |
|
52
|
|
|
->with('height', number_format($height, 0)) |
|
53
|
|
|
->with('width', $width) |
|
54
|
|
|
->with('original_height', $original_height) |
|
55
|
|
|
->with('original_width', $original_width) |
|
56
|
|
|
->with('scaled', $scaled) |
|
57
|
|
|
->with('ratio', $ratio); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function performResize($overWrite = true) |
|
61
|
|
|
{ |
|
62
|
|
|
$image_name = request('img'); |
|
|
|
|
|
|
63
|
|
|
$image_path = $this->lfm->setName(request('img'))->path('absolute'); |
|
|
|
|
|
|
64
|
|
|
$resize_path = $image_path; |
|
65
|
|
|
|
|
66
|
|
|
if (! $overWrite) { |
|
67
|
|
|
$fileParts = explode('.', $image_name); |
|
68
|
|
|
$fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_resized_' . time(); |
|
69
|
|
|
$resize_path = $this->lfm->setName(implode('.', $fileParts))->path('absolute'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
event(new ImageIsResizing($image_path)); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
if (class_exists(InterventionImageV2::class)) { |
|
75
|
|
|
InterventionImageV2::make($image_path) |
|
76
|
|
|
->resize(request('dataWidth'), request('dataHeight')) |
|
77
|
|
|
->save($resize_path); |
|
78
|
|
|
} else { |
|
79
|
|
|
InterventionImageV3::read($image_path) |
|
80
|
|
|
->resize(request('dataWidth'), request('dataHeight')) |
|
81
|
|
|
->save($resize_path); |
|
82
|
|
|
} |
|
83
|
|
|
event(new ImageWasResized($image_path)); |
|
84
|
|
|
|
|
85
|
|
|
return parent::$success_response; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function performResizeNew() |
|
89
|
|
|
{ |
|
90
|
|
|
$this->performResize(false); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
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