Skip to content

Commit

Permalink
support intervention/image v3
Browse files Browse the repository at this point in the history
  • Loading branch information
MeeDNite committed Apr 6, 2024
1 parent 539a190 commit ff217fe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/Controllers/CropController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
15 changes: 12 additions & 3 deletions src/Controllers/ResizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ff217fe

Please sign in to comment.