forked from leftypol/leftypol
MediaHandler: add handle indirection
This commit is contained in:
parent
f3ce9bf055
commit
461650a665
3 changed files with 18 additions and 4 deletions
|
@ -23,9 +23,12 @@ class FallbackMediaHandler implements MediaHandler {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function openHandle(string $file_path, string $file_mime): mixed {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function generateThumb(
|
||||
string $source_file_path,
|
||||
string $source_file_mime,
|
||||
mixed $handle,
|
||||
string $preferred_out_file_path,
|
||||
string $preferred_out_mime,
|
||||
int $max_width,
|
||||
|
|
|
@ -81,14 +81,23 @@ class GdMediaHandler implements MediaHandler {
|
|||
|| ($mime === 'image/avif' && self::PHP81 && $info['AVIF Support']);
|
||||
}
|
||||
|
||||
public function openHandle(string $file_path, string $file_mime): mixed {
|
||||
$gd = self::imageCreateFrom($file_path, $file_mime);
|
||||
if ($gd === false) {
|
||||
throw new \RuntimeException("Could not open '$file_path'");
|
||||
}
|
||||
return [ $gd, $file_path, $file_mime ];
|
||||
}
|
||||
|
||||
public function generateThumb(
|
||||
string $source_file_path,
|
||||
string $source_file_mime,
|
||||
mixed $handle,
|
||||
string $preferred_out_file_path,
|
||||
string $preferred_out_mime,
|
||||
int $max_width,
|
||||
int $max_height
|
||||
): ThumbGenerationResult {
|
||||
list($gd, $source_file_path, $source_file_mime) = $handle;
|
||||
|
||||
$gd = self::imageCreateFrom($source_file_path, $source_file_mime);
|
||||
if ($gd === false) {
|
||||
throw new \RuntimeException("Could not open '$source_file_path'");
|
||||
|
|
|
@ -7,6 +7,8 @@ use Vichan\Data\ThumbGenerationResult;
|
|||
interface MediaHandler {
|
||||
public function supportsMime(string $mime): bool;
|
||||
|
||||
public function openHandle(string $file_path, string $file_mime): mixed;
|
||||
|
||||
/**
|
||||
* Generates a thumbnail from the given file.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue