forked from leftypol/leftypol
ThumbGenerator: update
This commit is contained in:
parent
29684043ab
commit
e4087c61c1
2 changed files with 26 additions and 13 deletions
|
@ -5,16 +5,18 @@ use Vichan\Data\ThumbGenerationResult;
|
|||
|
||||
|
||||
class FallbackThumbGenerator implements ThumbGenerator {
|
||||
private string $thumb_path;
|
||||
private string $thumb_width;
|
||||
private string $thumb_height;
|
||||
private string $path;
|
||||
private int $width;
|
||||
private int $height;
|
||||
private string $mime;
|
||||
|
||||
|
||||
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 __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 {
|
||||
|
@ -23,16 +25,18 @@ class FallbackThumbGenerator implements ThumbGenerator {
|
|||
|
||||
public function generateThumb(
|
||||
string $source_file_path,
|
||||
string $preferred_out_file_path,
|
||||
string $source_file_mime,
|
||||
string $preferred_out_file_path,
|
||||
string $preferred_out_mime,
|
||||
int $max_width,
|
||||
int $max_height
|
||||
): ThumbGenerationResult {
|
||||
$res = new ThumbGenerationResult();
|
||||
$res->thumb_file_path = $this->thumb_path;
|
||||
$res->thumb_file_path = $this->path;
|
||||
$res->thumb_mime = $this->mime;
|
||||
$res->is_thumb_file_temporary = false;
|
||||
$res->width = \min($this->thumb_width, $max_width);
|
||||
$res->height = \min($this->thumb_height, $max_height);
|
||||
$res->width = \min($this->width, $max_width);
|
||||
$res->height = \min($this->height, $max_height);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,19 @@ interface ThumbGenerator {
|
|||
* Generates a thumbnail from the given file.
|
||||
*
|
||||
* @param string $source_file_path
|
||||
* @param string $source_file_mime
|
||||
* @param string $preferred_out_file_path
|
||||
* @param string $preferred_out_mime
|
||||
* @param int $max_width
|
||||
* @param int $max_height
|
||||
* @return ThumbGenerationResult
|
||||
*/
|
||||
public function generateThumb(string $source_file_path, string $source_file_mime, string $preferred_out_file_path, int $max_width, int $max_height): ThumbGenerationResult;
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue