forked from leftypol/leftypol
37 lines
1,003 B
PHP
37 lines
1,003 B
PHP
<?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;
|
|
}
|
|
}
|