Skip to content

Commit

Permalink
Merge pull request #1216 from rashidul-hasan/master
Browse files Browse the repository at this point in the history
Feat: Add option to store original image before resizing
  • Loading branch information
streamtw authored Mar 20, 2024
2 parents 9ce9b47 + 0e0125b commit b185d8d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/Controllers/ResizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,27 @@ public function getResize()
->with('ratio', $ratio);
}

public function performResize()
public function performResize($overWrite = true)
{
$image_name = request('img');
$image_path = $this->lfm->setName(request('img'))->path('absolute');
$resize_path = $image_path;

if (! $overWrite) {
$fileParts = explode('.', $image_name);
$fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_resized_' . time();
$resize_path = $this->lfm->setName(implode('.', $fileParts))->path('absolute');
}

event(new ImageIsResizing($image_path));
Image::make($image_path)->resize(request('dataWidth'), request('dataHeight'))->save();
Image::make($image_path)->resize(request('dataWidth'), request('dataHeight'))->save($resize_path);
event(new ImageWasResized($image_path));

return parent::$success_response;
}

public function performResizeNew()
{
$this->performResize(false);
}
}
5 changes: 4 additions & 1 deletion src/Lfm.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ public static function routes()
'uses' => 'ResizeController@performResize',
'as' => 'performResize',
]);

Route::get('/doresizenew', [
'uses' => 'ResizeController@performResizeNew',
'as' => 'performResizeNew',
]);
// download
Route::get('/download', [
'uses' => 'DownloadController@getDownload',
Expand Down
1 change: 1 addition & 0 deletions src/lang/en/lfm.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
'btn-cancel' => 'Cancel',
'btn-confirm' => 'Confirm',
'btn-resize' => 'Resize',
'btn-resize-copy' => 'Copy & Resize',
'btn-open' => 'Open Folder',

'resize-ratio' => 'Ratio:',
Expand Down
9 changes: 9 additions & 0 deletions src/views/resize.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
</table>
<div class="d-flex mb-3">
<button class="btn btn-secondary w-50 mr-1" onclick="loadItems()">{{ trans('laravel-filemanager::lfm.btn-cancel') }}</button>
<button class="btn btn-warning w-50 mr-1" onclick="doResizeNew()">{{ trans('laravel-filemanager::lfm.btn-resize-copy') }}</button>
<button class="btn btn-primary w-50" onclick="doResize()">{{ trans('laravel-filemanager::lfm.btn-resize') }}</button>
</div>

Expand Down Expand Up @@ -120,4 +121,12 @@ function doResize() {
dataWidth: $("#width").val()
}).done(loadItems);
}
function doResizeNew() {
performLfmRequest('doresizenew', {
img: $("#img").val(),
dataHeight: $("#height").val(),
dataWidth: $("#width").val()
}).done(loadItems);
}
</script>

0 comments on commit b185d8d

Please sign in to comment.