diff --git a/composer.json b/composer.json index 6f72cf036..dfb35a580 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ "code16/laravel-content-renderer": "^1.1", "inertiajs/inertia-laravel": "^2.0", "intervention/image": "^3.4", - "intervention/image-laravel": "^1.2", "laravel/framework": "^11.0", "laravel/prompts": "0.*", "league/commonmark": "^2.4", diff --git a/src/Form/Eloquent/Uploads/Thumbnails/SharpImageManager.php b/src/Form/Eloquent/Uploads/Thumbnails/SharpImageManager.php new file mode 100644 index 000000000..456e462de --- /dev/null +++ b/src/Form/Eloquent/Uploads/Thumbnails/SharpImageManager.php @@ -0,0 +1,40 @@ +manager = new ImageManager(sharp()->config()->get('uploads.image_driver')); + } + + public function create(int $width, int $height): ImageInterface + { + return $this->manager->create($width, $height); + } + + public function read(mixed $input, array|string|DecoderInterface $decoders = []): ImageInterface + { + return $this->manager->read($input, $decoders); + } + + public function animate(callable $init): ImageInterface + { + return $this->manager->animate($init); + } + + public function driver(): DriverInterface + { + return $this->manager->driver(); + } +} diff --git a/src/Form/Eloquent/Uploads/Thumbnails/Thumbnail.php b/src/Form/Eloquent/Uploads/Thumbnails/Thumbnail.php index 567f4aca5..282d9b6f1 100644 --- a/src/Form/Eloquent/Uploads/Thumbnails/Thumbnail.php +++ b/src/Form/Eloquent/Uploads/Thumbnails/Thumbnail.php @@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Illuminate\Support\Traits\Conditionable; -use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Encoders\AvifEncoder; use Intervention\Image\Encoders\FilePathEncoder; use Intervention\Image\Encoders\GifEncoder; @@ -18,14 +17,13 @@ use Intervention\Image\Encoders\WebpEncoder; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Exceptions\EncoderException; -use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\EncoderInterface; class Thumbnail { use Conditionable; - protected ImageManager $imageManager; + protected SharpImageManager $imageManager; protected ?SharpUploadModel $uploadModel = null; protected ?string $encoderClass = null; protected int $quality = 90; @@ -38,7 +36,7 @@ public function __construct(?SharpUploadModel $model = null) { $this->uploadModel = $model; $this->transformationFilters = $model?->filters; - $this->imageManager = new ImageManager(new Driver()); + $this->imageManager = app(SharpImageManager::class); } public function setQuality(int $quality): self diff --git a/src/Http/Jobs/HandleTransformedFileJob.php b/src/Http/Jobs/HandleTransformedFileJob.php index 534637a69..98e704c2d 100644 --- a/src/Http/Jobs/HandleTransformedFileJob.php +++ b/src/Http/Jobs/HandleTransformedFileJob.php @@ -2,13 +2,13 @@ namespace Code16\Sharp\Http\Jobs; +use Code16\Sharp\Form\Eloquent\Uploads\Thumbnails\SharpImageManager; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Storage; -use Intervention\Image\ImageManager; class HandleTransformedFileJob implements ShouldQueue { @@ -22,7 +22,7 @@ public function __construct( public array $transformFilters, ) {} - public function handle(ImageManager $imageManager): void + public function handle(SharpImageManager $imageManager): void { $img = $imageManager->read(Storage::disk($this->disk)->get($this->filePath)); diff --git a/src/SharpInternalServiceProvider.php b/src/SharpInternalServiceProvider.php index 68dcb548f..0e11b782f 100644 --- a/src/SharpInternalServiceProvider.php +++ b/src/SharpInternalServiceProvider.php @@ -29,6 +29,7 @@ use Code16\Sharp\Console\ShowPageMakeCommand; use Code16\Sharp\Exceptions\SharpTokenMismatchException; use Code16\Sharp\Form\Eloquent\Uploads\Migration\CreateUploadsMigration; +use Code16\Sharp\Form\Eloquent\Uploads\Thumbnails\SharpImageManager; use Code16\Sharp\Http\Context\CurrentSharpRequest; use Code16\Sharp\Http\Middleware\AddLinkHeadersForPreloadedRequests; use Code16\Sharp\Http\Middleware\SharpAuthenticate; @@ -46,7 +47,6 @@ use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; use Inertia\ServiceProvider as InertiaServiceProvider; -use Intervention\Image\ImageManager; class SharpInternalServiceProvider extends ServiceProvider { @@ -100,10 +100,7 @@ public function register() ? new SharpLegacyConfigBuilder() : new SharpConfigBuilder() ); - $this->app->singleton( - ImageManager::class, - fn () => new ImageManager(sharp()->config()->get('uploads.image_driver')) - ); + $this->app->singleton(SharpImageManager::class); $this->app->singleton(AddLinkHeadersForPreloadedRequests::class); if (class_exists('\PragmaRX\Google2FA\Google2FA')) { @@ -128,7 +125,6 @@ public function register() : null; }); - $this->app->register(\Intervention\Image\Laravel\ServiceProvider::class); $this->app->register(InertiaServiceProvider::class); }