Skip to content

Commit 539a190

Browse files
committed
feat: implement support for intervention/image v3
1 parent cb0d0ba commit 539a190

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/Controllers/CropController.php

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function getCropImage($overWrite = true)
4242
$crop_info = request()->only('dataWidth', 'dataHeight', 'dataX', 'dataY');
4343

4444
// crop image
45+
// TODO: support intervention/image v3
4546
Image::make($image_path)
4647
->crop(...array_values($crop_info))
4748
->save($crop_path);

src/Controllers/ResizeController.php

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function performResize($overWrite = true)
6565
}
6666

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

src/LfmPath.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace UniSharp\LaravelFilemanager;
44

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

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

328-
$this->storage->put($image->stream()->detach(), 'public');
326+
if (class_exists(InterventionImageV2::class)) {
327+
$encoded_image = InterventionImageV2::make($original_image->get())
328+
->fit($thumbWidth, $thumbHeight)
329+
->stream()
330+
->detach();
331+
} else {
332+
$encoded_image = InterventionImageV3::read($original_image->get())
333+
->cover($thumbWidth, $thumbHeight)
334+
->encodeByMediaType();
335+
}
336+
337+
338+
$this->storage->put($encoded_image, 'public');
329339
}
330340
}

0 commit comments

Comments
 (0)