From 0e0125b6fd55a5a14d94d9ccd420b76d30c9a37a Mon Sep 17 00:00:00 2001 From: rashidul Date: Sun, 25 Feb 2024 12:46:37 +0600 Subject: [PATCH] Feat: Add option to store original image before resizing Added a 'Copy & Resize' button on the resize window which will keep the original image & create a new image with new size. --- src/Controllers/ResizeController.php | 17 +++++++++++++++-- src/Lfm.php | 5 ++++- src/lang/en/lfm.php | 1 + src/views/resize.blade.php | 9 +++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Controllers/ResizeController.php b/src/Controllers/ResizeController.php index 39693734..52092d14 100644 --- a/src/Controllers/ResizeController.php +++ b/src/Controllers/ResizeController.php @@ -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); + } } diff --git a/src/Lfm.php b/src/Lfm.php index bd07d8b8..371cbca8 100644 --- a/src/Lfm.php +++ b/src/Lfm.php @@ -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', diff --git a/src/lang/en/lfm.php b/src/lang/en/lfm.php index fa5e8750..3945f714 100644 --- a/src/lang/en/lfm.php +++ b/src/lang/en/lfm.php @@ -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:', diff --git a/src/views/resize.blade.php b/src/views/resize.blade.php index f4134f75..121e922f 100644 --- a/src/views/resize.blade.php +++ b/src/views/resize.blade.php @@ -59,6 +59,7 @@
+
@@ -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); + }