WIP
This commit is contained in:
58
app/Importers/Image/Jobs/GenerateFullscreen.php
Normal file
58
app/Importers/Image/Jobs/GenerateFullscreen.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Importers\Image\Jobs;
|
||||
|
||||
use App\Models\Image;
|
||||
use Illuminate\Bus\Batchable;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\Laravel\Facades\Image as InterventionImage;
|
||||
use \Throwable;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GenerateFullscreen implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Batchable;
|
||||
|
||||
public string $source;
|
||||
public string $destination;
|
||||
|
||||
public function __construct(public Image $image)
|
||||
{
|
||||
$this->source = Storage::disk('images')->path($this->image->album_id . '/original/' . $this->image->id . '.avif');
|
||||
$this->destination = $this->image->album_id . '/lightbox/' . $this->image->id . '.avif';
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if ($this->batch()->cancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$image = InterventionImage::read($this->source);
|
||||
if($image->width() >= $image->height()) {
|
||||
// landscape
|
||||
$image->scaleDown(width: config('gallery.image.fullscreen.maxWidth', 2000));
|
||||
} else {
|
||||
// portrait
|
||||
$image->scaleDown(height: config('gallery.image.fullscreen.maxHeight', 2000));
|
||||
}
|
||||
|
||||
Storage::disk('images')->put($this->destination, $image->toAvif(config('gallery.image.quality', 80)));
|
||||
}
|
||||
|
||||
public function failed(?Throwable $exception): void
|
||||
{
|
||||
$this->image->delete();
|
||||
|
||||
Log::error($exception, [
|
||||
'image' => $this->image,
|
||||
'source' => $this->source,
|
||||
'destination' => $this->destination
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user