forked from leftypol/leftypol
GdMediaHandler.php: handle file kind
This commit is contained in:
parent
ff517f0be8
commit
4bbb5f00a4
1 changed files with 11 additions and 5 deletions
|
@ -81,12 +81,12 @@ class GdMediaHandler implements MediaHandler {
|
|||
|| ($mime === 'image/avif' && self::PHP81 && $info['AVIF Support']);
|
||||
}
|
||||
|
||||
public function openHandle(string $file_path, string $file_mime): mixed {
|
||||
public function openHandle(string $file_path, string $file_mime, int $file_kind): 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 ];
|
||||
return [ $gd, $file_path, $file_mime, $file_kind ];
|
||||
}
|
||||
|
||||
public function generateThumb(
|
||||
|
@ -96,7 +96,7 @@ class GdMediaHandler implements MediaHandler {
|
|||
int $max_width,
|
||||
int $max_height
|
||||
): ThumbGenerationResult {
|
||||
list($gd, $source_file_path, $source_file_mime) = $handle;
|
||||
list($gd, $source_file_path, $source_file_mime, $source_file_kind) = $handle;
|
||||
|
||||
$gd = self::imageCreateFrom($source_file_path, $source_file_mime);
|
||||
if ($gd === false) {
|
||||
|
@ -109,8 +109,14 @@ class GdMediaHandler implements MediaHandler {
|
|||
if ($width <= $max_width && $height <= $max_height) {
|
||||
$out_path = $preferred_out_file_path . '.' . self::MIME_TO_EXT[$source_file_mime];
|
||||
|
||||
if (!Fs\link_or_copy($source_file_path, $out_path)) {
|
||||
throw new \RuntimeException("Could not link or copy '$source_file_path' to '$out_path'");
|
||||
if ($source_file_kind === self::FILE_KIND_UPLOADED) {
|
||||
if (!Fs\move_or_copy_uploaded($source_file_path, $out_path)) {
|
||||
throw new \RuntimeException("Could not move or copy uploaded file '$source_file_path' to '$out_path'");
|
||||
}
|
||||
} else {
|
||||
if (!Fs\link_or_copy($source_file_path, $out_path)) {
|
||||
throw new \RuntimeException("Could not link or copy '$source_file_path' to '$out_path'");
|
||||
}
|
||||
}
|
||||
|
||||
return new ThumbGenerationResult(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue