WIP
This commit is contained in:
51
app/Importers/Image/Jobs/FinishImageModification.php
Normal file
51
app/Importers/Image/Jobs/FinishImageModification.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?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 \Throwable;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FinishImageModification implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Batchable;
|
||||
|
||||
public function __construct(public Image $image)
|
||||
{
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if (method_exists($this, 'batch') && $this->batch()?->cancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->image->fill([
|
||||
'isCover' => $this->getCoverFlag(),
|
||||
'isProcessing' => false,
|
||||
]);
|
||||
$this->image->save();
|
||||
|
||||
// TODO: Dispatch image cleaned event
|
||||
}
|
||||
|
||||
private function getCoverFlag() : bool {
|
||||
if(!$this->image->album->hasCover && $this->image->album->images->sortBy('id')->first()->id == $this->image->id) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function failed(?Throwable $exception): void
|
||||
{
|
||||
Log::error($exception, [
|
||||
'image' => $this->image,
|
||||
]);
|
||||
}
|
||||
}
|
||||
50
app/Importers/Image/Jobs/RotateImage.php
Normal file
50
app/Importers/Image/Jobs/RotateImage.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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 RotateImage implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Batchable;
|
||||
|
||||
public string $source;
|
||||
public string $destination;
|
||||
|
||||
public function __construct(public Image $image, public int $degrees)
|
||||
{
|
||||
$this->source = Storage::disk('images')->path($this->image->album_id . '/original/' . $this->image->id . '.avif');
|
||||
$this->destination = $this->image->album_id . '/original/' . $this->image->id . '.avif';
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if (method_exists($this, 'batch') && $this->batch()?->cancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rotated = InterventionImage::read($this->source);
|
||||
$rotated = $rotated->rotate($this->degrees);
|
||||
|
||||
Storage::disk('images')->put($this->destination, $rotated->toAvif(config('gallery.image.quality', 80)));
|
||||
}
|
||||
|
||||
public function failed(?Throwable $exception): void
|
||||
{
|
||||
Log::error($exception, [
|
||||
'image' => $this->image,
|
||||
'source' => $this->source,
|
||||
'destination' => $this->destination
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user