Skip to content

Commit

Permalink
feat: handle colorize
Browse files Browse the repository at this point in the history
  • Loading branch information
psion-ar committed Oct 18, 2024
1 parent 9866f7a commit 1b6be26
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions app/Actions/Handler/HandleColorize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace App\Actions\Handler;

use App\Contracts\Actions\SavesImage;
use App\DTOs\Request;
use App\Services\Metrics;
use Spatie\Image\Image;

use function Laravel\Prompts\progress;

final class HandleColorize
{
private Request $request;

public function __construct(private SavesImage $save) {}

public function __invoke(Request $request): Metrics
{
$this->request = $request;
unset($request);

$progress = fn () => progress(
label: 'Processing images...',
steps: $this->request->images,
callback: function (Image $image) {
$this->applyColorize($image);
($this->save)($image, $this->request->target, $this->request->format);
},
);

return new Metrics($progress, $this->request->images->count());
}

private function applyColorize(Image $image): void
{
$image->colorize($this->request->red, $this->request->green, $this->request->blue);
}
}

0 comments on commit 1b6be26

Please sign in to comment.