Skip to content

Commit a6733bb

Browse files
Willem Leuverinkstreamtw
authored andcommitted
Copy and crop (#335)
* added a helper method that overrides ini settings configured in lfm config. This method is applied before file upload but can be used in every LfmController if nessecary in the future * moved ini override to the LfmController's constructor so it's always executed * Update lfm.php removed upload_max_filesize option as it doesn't work in this context because the request was already sent * resolving merge conflicts after updating with unisharp upstream * added 'Copy & Crop' option in crop pop-up * removed some additions that are no longer used * removed some additions that are no longer used
1 parent 879b290 commit a6733bb

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

src/controllers/CropController.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,36 @@ public function getCrop()
2929
/**
3030
* Crop the image (called via ajax)
3131
*/
32-
public function getCropimage()
32+
public function getCropimage($overWrite = true)
3333
{
3434
$dataX = request('dataX');
3535
$dataY = request('dataY');
3636
$dataHeight = request('dataHeight');
3737
$dataWidth = request('dataWidth');
3838
$image_path = parent::getCurrentPath(request('img'));
39+
$crop_path = $image_path;
40+
41+
if(!$overWrite) {
42+
$fileParts = explode('.', request('img'));
43+
$fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_cropped_' . time();
44+
$crop_path = parent::getCurrentPath(implode('.', $fileParts));
45+
}
3946

4047
event(new ImageIsCropping($image_path));
4148
// crop image
4249
Image::make($image_path)
4350
->crop($dataWidth, $dataHeight, $dataX, $dataY)
44-
->save($image_path);
51+
->save($crop_path);
4552

4653
// make new thumbnail
47-
Image::make($image_path)
54+
Image::make($crop_path)
4855
->fit(config('lfm.thumb_img_width', 200), config('lfm.thumb_img_height', 200))
49-
->save(parent::getThumbPath(parent::getName($image_path)));
56+
->save(parent::getThumbPath(parent::getName($crop_path)));
5057
event(new ImageWasCropped($image_path));
5158
}
59+
60+
public function getNewCropimage (){
61+
62+
$this->getCropimage(false);
63+
}
5264
}

src/lang/en/lfm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
'btn-uploading' => 'Uploading...',
6060
'btn-close' => 'Close',
6161
'btn-crop' => 'Crop',
62+
'btn-copy-crop' => 'Copy & Crop',
6263
'btn-cancel' => 'Cancel',
6364
'btn-resize' => 'Resize',
6465

src/lang/nl/lfm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
'btn-uploading' => 'Uploaden...',
5858
'btn-close' => 'Sluiten',
5959
'btn-crop' => 'Bijsnijden',
60+
'btn-copy-crop' => 'Kopiëren & Bijsnijden',
6061
'btn-cancel' => 'Annuleren',
6162
'btn-resize' => 'Formaat aanpassen',
6263

src/routes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
'uses' => 'CropController@getCropimage',
5858
'as' => 'getCropimage'
5959
]);
60+
Route::get('/cropnewimage', [
61+
'uses' => 'CropController@getNewCropimage',
62+
'as' => 'getCropimage'
63+
]);
6064

6165
// rename
6266
Route::get('/rename', [

src/views/crop.blade.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<br>
3232

3333
<button class="btn btn-primary" onclick="performCrop()">{{ trans('laravel-filemanager::lfm.btn-crop') }}</button>
34+
<button class="btn btn-primary" onclick="performCropNew()">{{ trans('laravel-filemanager::lfm.btn-copy-crop') }}</button>
3435
<button class="btn btn-info" onclick="loadItems()">{{ trans('laravel-filemanager::lfm.btn-cancel') }}</button>
3536
<form id='cropForm'>
3637
<input type="hidden" id="img" name="img" value="{{ $img->name }}">
@@ -90,4 +91,16 @@ function performCrop() {
9091
type: $('#type').val()
9192
}).done(loadItems);
9293
}
94+
95+
function performCropNew() {
96+
performLfmRequest('cropnewimage', {
97+
img: $("#img").val(),
98+
working_dir: $("#working_dir").val(),
99+
dataX: $("#dataX").val(),
100+
dataY: $("#dataY").val(),
101+
dataHeight: $("#dataHeight").val(),
102+
dataWidth: $("#dataWidth").val(),
103+
type: $('#type').val()
104+
}).done(loadItems);
105+
}
93106
</script>

0 commit comments

Comments
 (0)