Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions src/Form/Eloquent/Uploads/Thumbnails/SharpImageManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Code16\Sharp\Form\Eloquent\Uploads\Thumbnails;


use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ImageManagerInterface;

class SharpImageManager implements ImageManagerInterface
{
protected ImageManager $manager;

public function __construct()
{
$this->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();
}
}
6 changes: 2 additions & 4 deletions src/Form/Eloquent/Uploads/Thumbnails/Thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Jobs/HandleTransformedFileJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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));

Expand Down
8 changes: 2 additions & 6 deletions src/SharpInternalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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')) {
Expand All @@ -128,7 +125,6 @@ public function register()
: null;
});

$this->app->register(\Intervention\Image\Laravel\ServiceProvider::class);
$this->app->register(InertiaServiceProvider::class);
}

Expand Down
Loading