leftypol/inc/Service/Media/FallbackMediaHandler.php

43 lines
972 B
PHP
Raw Normal View History

<?php
namespace Vichan\Service\Media;
use Vichan\Data\ThumbGenerationResult;
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-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;
}
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,
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)
);
}
}