Skip to content

Commit b427ce5

Browse files
committed
Refactoring
1 parent 1c90d52 commit b427ce5

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

src/Controllers/CropController.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@ public function getCrop()
2424

2525
/**
2626
* Crop the image (called via ajax).
27+
*
28+
* @param bool $overWrite
2729
*/
2830
public function getCropimage($overWrite = true)
2931
{
3032
$image_name = request('img');
33+
$target_name = $image_name;
3134
$image_path = $this->lfm->setName($image_name)->path('absolute');
3235

33-
if (! $overWrite) {
34-
$fileParts = explode('.', $image_name);
35-
$fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_cropped_' . time();
36-
$crop_name = implode('.', $fileParts);
37-
}
38-
3936
event(new ImageIsCropping($image_path));
4037

4138
$crop_info = request()->only('dataWidth', 'dataHeight', 'dataX', 'dataY');
@@ -46,19 +43,24 @@ public function getCropimage($overWrite = true)
4643
->stream()
4744
->detach();
4845

49-
if (! $overWrite) {
50-
$this->lfm->setName($crop_name)->storage->put($croppedImage);
51-
// make new thumbnail
52-
$this->lfm->makeThumbnail($crop_name);
53-
} else {
54-
$this->lfm->setName($image_name)->storage->put($croppedImage);
55-
// make new thumbnail
56-
$this->lfm->makeThumbnail($image_name);
46+
// Overwrite
47+
if (!$overWrite) {
48+
$fileParts = explode('.', $image_name);
49+
$fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_cropped_' . time();
50+
$target_name = implode('.', $fileParts);
5751
}
5852

53+
// Replace or create new image
54+
$this->lfm->setName($target_name)->storage->put($croppedImage, 'public');
55+
// make new thumbnail
56+
$this->lfm->makeThumbnail($target_name);
57+
5958
event(new ImageWasCropped($image_path));
6059
}
6160

61+
/**
62+
* Crop the image (called via ajax).
63+
*/
6264
public function getNewCropimage()
6365
{
6466
$this->getCropimage(false);

src/Controllers/ResizeController.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class ResizeController extends LfmController
1010
{
1111
/**
12-
* Dipsplay image for resizing.
12+
* Display image for resizing.
1313
*
1414
* @return mixed
1515
*/
@@ -52,14 +52,25 @@ public function getResize()
5252
->with('ratio', $ratio);
5353
}
5454

55+
/**
56+
* Perform resize
57+
*
58+
* @return string
59+
*/
5560
public function performResize()
5661
{
5762
$image_name = request('img');
5863
$image_path = $this->lfm->setName($image_name)->path('absolute');
5964

6065
event(new ImageIsResizing($image_path));
61-
$resizedImage = Image::make($this->lfm->setName($image_name)->storage->get())->resize(request('dataWidth'), request('dataHeight'))->stream()->detach();
62-
$this->lfm->setName($image_name)->storage->put($resizedImage);
66+
67+
$image = $this->lfm->setName($image_name)->storage->get();
68+
$resizedImage = Image::make($image)->resize(request('dataWidth'), request('dataHeight'))
69+
->stream()
70+
->detach();
71+
72+
// Same new image
73+
$this->lfm->setName($image_name)->storage->put($resizedImage, 'public');
6374
// make new thumbnail
6475
$this->lfm->makeThumbnail($image_name);
6576

0 commit comments

Comments
 (0)