2025-03-17 22:22:23 +01:00
|
|
|
<?php
|
|
|
|
namespace Vichan\Service\Media;
|
|
|
|
|
|
|
|
use Vichan\Data\ThumbGenerationResult;
|
|
|
|
|
|
|
|
|
|
|
|
class FallbackThumbGenerator implements ThumbGenerator {
|
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 {
|
|
|
|
$res = new ThumbGenerationResult();
|
2025-03-18 00:40:51 +01:00
|
|
|
$res->thumb_file_path = $this->path;
|
|
|
|
$res->thumb_mime = $this->mime;
|
2025-03-17 22:22:23 +01:00
|
|
|
$res->is_thumb_file_temporary = false;
|
2025-03-18 00:40:51 +01:00
|
|
|
$res->width = \min($this->width, $max_width);
|
|
|
|
$res->height = \min($this->height, $max_height);
|
2025-03-17 22:22:23 +01:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
}
|