2025-03-17 22:22:23 +01:00
|
|
|
<?php
|
|
|
|
namespace Vichan\Service\Media;
|
|
|
|
|
|
|
|
use Vichan\Data\ThumbGenerationResult;
|
|
|
|
|
|
|
|
|
2025-03-18 11:26:30 +01:00
|
|
|
class FallbackMediaHandler implements MediaHandler {
|
2025-03-18 00:40:51 +01:00
|
|
|
private string $path;
|
|
|
|
private int $width;
|
|
|
|
private int $height;
|
|
|
|
private string $mime;
|
2025-03-17 22:22:23 +01:00
|
|
|
|
|
|
|
|
2025-03-18 00:40:51 +01:00
|
|
|
public function __construct(ImageMetadataReader $image_metadate_reader, string $default_thumb_path) {
|
|
|
|
$res = $image_metadate_reader->getMetadata($default_thumb_path);
|
|
|
|
$this->path = $default_thumb_path;
|
|
|
|
$this->width = $res->width;
|
|
|
|
$this->height = $res->height;
|
|
|
|
$this->mime = $res->mime;
|
2025-03-17 22:22:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function supportsMime(string $mime): bool {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generateThumb(
|
|
|
|
string $source_file_path,
|
2025-03-17 22:26:18 +01:00
|
|
|
string $source_file_mime,
|
2025-03-18 00:40:51 +01:00
|
|
|
string $preferred_out_file_path,
|
|
|
|
string $preferred_out_mime,
|
2025-03-17 22:22:23 +01:00
|
|
|
int $max_width,
|
|
|
|
int $max_height
|
|
|
|
): ThumbGenerationResult {
|
2025-03-18 10:09:19 +01:00
|
|
|
return new ThumbGenerationResult(
|
|
|
|
$this->path,
|
|
|
|
$this->mime,
|
|
|
|
false,
|
|
|
|
\min($this->width, $max_width),
|
|
|
|
\min($this->height, $max_height)
|
|
|
|
);
|
2025-03-17 22:22:23 +01:00
|
|
|
}
|
|
|
|
}
|