Skip to content

Commit

Permalink
feat: implement support for intervention/image v3
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed Apr 3, 2024
1 parent cb0d0ba commit 539a190
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Controllers/CropController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getCropImage($overWrite = true)
$crop_info = request()->only('dataWidth', 'dataHeight', 'dataX', 'dataY');

// crop image
// TODO: support intervention/image v3
Image::make($image_path)
->crop(...array_values($crop_info))
->save($crop_path);
Expand Down
1 change: 1 addition & 0 deletions src/Controllers/ResizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function performResize($overWrite = true)
}

event(new ImageIsResizing($image_path));
// TODO: support intervention/image v3
Image::make($image_path)->resize(request('dataWidth'), request('dataHeight'))->save($resize_path);
event(new ImageWasResized($image_path));

Expand Down
20 changes: 15 additions & 5 deletions src/LfmPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace UniSharp\LaravelFilemanager;

use Illuminate\Container\Container;
use Intervention\Image\Facades\Image;
use Intervention\Image\Facades\Image as InterventionImageV2;
use Intervention\Image\Laravel\Facades\Image as InterventionImageV3;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use UniSharp\LaravelFilemanager\Events\FileIsUploading;
use UniSharp\LaravelFilemanager\Events\FileWasUploaded;
Expand Down Expand Up @@ -234,7 +235,6 @@ public function upload($file)
\Log::info($e);
return $this->error('invalid');
}
// TODO should be "FileWasUploaded"
event(new FileWasUploaded($new_file_path));
event(new ImageWasUploaded($new_file_path));

Expand Down Expand Up @@ -322,9 +322,19 @@ public function generateThumbnail($file_name)
$this->setName($file_name)->thumb(true);
$thumbWidth = $this->helper->shouldCreateCategoryThumb() && $this->helper->categoryThumbWidth() ? $this->helper->categoryThumbWidth() : config('lfm.thumb_img_width', 200);
$thumbHeight = $this->helper->shouldCreateCategoryThumb() && $this->helper->categoryThumbHeight() ? $this->helper->categoryThumbHeight() : config('lfm.thumb_img_height', 200);
$image = Image::make($original_image->get())
->fit($thumbWidth, $thumbHeight);

$this->storage->put($image->stream()->detach(), 'public');
if (class_exists(InterventionImageV2::class)) {
$encoded_image = InterventionImageV2::make($original_image->get())
->fit($thumbWidth, $thumbHeight)
->stream()
->detach();
} else {
$encoded_image = InterventionImageV3::read($original_image->get())
->cover($thumbWidth, $thumbHeight)
->encodeByMediaType();
}


$this->storage->put($encoded_image, 'public');
}
}

0 comments on commit 539a190

Please sign in to comment.