forked from leftypol/leftypol
ThumbGenerator: broaden scop to media handler
This commit is contained in:
parent
5f85ca7f44
commit
f3ce9bf055
3 changed files with 4 additions and 5 deletions
42
inc/Service/Media/FallbackMediaHandler.php
Normal file
42
inc/Service/Media/FallbackMediaHandler.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\ThumbGenerationResult;
|
||||
|
||||
|
||||
class FallbackMediaHandler implements MediaHandler {
|
||||
private string $path;
|
||||
private int $width;
|
||||
private int $height;
|
||||
private string $mime;
|
||||
|
||||
|
||||
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,
|
||||
string $source_file_mime,
|
||||
string $preferred_out_file_path,
|
||||
string $preferred_out_mime,
|
||||
int $max_width,
|
||||
int $max_height
|
||||
): ThumbGenerationResult {
|
||||
return new ThumbGenerationResult(
|
||||
$this->path,
|
||||
$this->mime,
|
||||
false,
|
||||
\min($this->width, $max_width),
|
||||
\min($this->height, $max_height)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue