Files
SkinbaseNova/app/Services/Vision/ArtworkVisionImageUrl.php

30 lines
701 B
PHP

<?php
declare(strict_types=1);
namespace App\Services\Vision;
use App\Models\Artwork;
use App\Services\ThumbnailService;
final class ArtworkVisionImageUrl
{
public function fromArtwork(Artwork $artwork): ?string
{
return $this->fromHash(
(string) ($artwork->hash ?? ''),
(string) ($artwork->thumb_ext ?: 'webp')
);
}
public function fromHash(?string $hash, ?string $ext = 'webp', string $size = 'md'): ?string
{
$clean = strtolower((string) preg_replace('/[^a-z0-9]/', '', (string) $hash));
if ($clean === '') {
return null;
}
return ThumbnailService::fromHash($clean, $ext, $size);
}
}