33 lines
866 B
PHP
33 lines
866 B
PHP
<?php
|
|
|
|
namespace Media\Entities;
|
|
|
|
use App\Framework\Database\Attributes\Entity;
|
|
|
|
#[Entity(tableName: 'image_variants')]
|
|
class ImageVariant
|
|
{
|
|
public function __construct(
|
|
public ?int $id = null,
|
|
public int $imageId = 0,
|
|
public string $variant = '', // 'thumbnail', 'small', 'medium', 'large'
|
|
public string $format = '', // 'jpg', 'webp', 'avif'
|
|
public int $width = 0,
|
|
public int $height = 0,
|
|
public int $fileSize = 0,
|
|
public string $filename = '',
|
|
public \DateTimeImmutable $createdAt = new \DateTimeImmutable(),
|
|
) {}
|
|
|
|
public function getFullPath(Image $image): string
|
|
{
|
|
return sprintf(
|
|
'%s/%s/%s.%s',
|
|
$image->getUploadDirectory(),
|
|
$image->getFilePathPattern(),
|
|
$this->variant,
|
|
$this->format
|
|
);
|
|
}
|
|
}
|