diff --git a/src/Controllers/CropController.php b/src/Controllers/CropController.php index b0f42a98..ba256e56 100644 --- a/src/Controllers/CropController.php +++ b/src/Controllers/CropController.php @@ -2,7 +2,8 @@ namespace UniSharp\LaravelFilemanager\Controllers; -use Intervention\Image\Facades\Image; +use Intervention\Image\Facades\Image as InterventionImageV2; +use Intervention\Image\Laravel\Facades\Image as InterventionImageV3; use UniSharp\LaravelFilemanager\Events\ImageIsCropping; use UniSharp\LaravelFilemanager\Events\ImageWasCropped; @@ -42,10 +43,15 @@ 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); + if (class_exists(InterventionImageV2::class)) { + InterventionImageV2::make($image_path) + ->crop(...array_values($crop_info)) + ->save($crop_path); + } else { + InterventionImageV3::read($image_path) + ->crop(...array_values($crop_info)) + ->save($crop_path); + } // make new thumbnail $this->lfm->generateThumbnail($image_name); diff --git a/src/Controllers/ResizeController.php b/src/Controllers/ResizeController.php index db9df29c..a3233926 100644 --- a/src/Controllers/ResizeController.php +++ b/src/Controllers/ResizeController.php @@ -2,7 +2,8 @@ namespace UniSharp\LaravelFilemanager\Controllers; -use Intervention\Image\Facades\Image; +use Intervention\Image\Facades\Image as InterventionImageV2; +use Intervention\Image\Laravel\Facades\Image as InterventionImageV3; use UniSharp\LaravelFilemanager\Events\ImageIsResizing; use UniSharp\LaravelFilemanager\Events\ImageWasResized; @@ -65,8 +66,16 @@ 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); + + if (class_exists(InterventionImageV2::class)) { + InterventionImageV2::make($image_path) + ->resize(request('dataWidth'), request('dataHeight')) + ->save($resize_path); + } else { + InterventionImageV3::read($image_path) + ->resize(request('dataWidth'), request('dataHeight')) + ->save($resize_path); + } event(new ImageWasResized($image_path)); return parent::$success_response;