forked from leftypol/leftypol
FallbackThumbGenerator.php: add fallbakc thumb generator
This commit is contained in:
parent
6d19717d28
commit
ac679951db
1 changed files with 37 additions and 0 deletions
37
inc/Service/Media/FallbackThumbGenerator.php
Normal file
37
inc/Service/Media/FallbackThumbGenerator.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\ThumbGenerationResult;
|
||||
|
||||
|
||||
class FallbackThumbGenerator implements ThumbGenerator {
|
||||
private string $thumb_path;
|
||||
private string $thumb_width;
|
||||
private string $thumb_height;
|
||||
|
||||
|
||||
public function __construct(ImageFormatReader $image_format_reader, string $default_thumb_path) {
|
||||
list($width, $height) = $image_format_reader->getSizes($default_thumb_path);
|
||||
$this->thumb_path = $default_thumb_path;
|
||||
$this->thumb_width = $width;
|
||||
$this->thumb_height = $height;
|
||||
}
|
||||
|
||||
public function supportsMime(string $mime): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function generateThumb(
|
||||
string $source_file_path,
|
||||
string $preferred_out_file_path,
|
||||
int $max_width,
|
||||
int $max_height
|
||||
): ThumbGenerationResult {
|
||||
$res = new ThumbGenerationResult();
|
||||
$res->thumb_file_path = $this->thumb_path;
|
||||
$res->is_thumb_file_temporary = false;
|
||||
$res->width = \min($this->thumb_width, $max_width);
|
||||
$res->height = \min($this->thumb_height, $max_height);
|
||||
return $res;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue