From db3b59e01878b3df2334ee4fa36e57be509599b4 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Fri, 28 Mar 2025 23:27:52 +0100 Subject: [PATCH] GdMediaHandler.php: implement installMedia --- inc/Service/Media/GdMediaHandler.php | 40 +++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/inc/Service/Media/GdMediaHandler.php b/inc/Service/Media/GdMediaHandler.php index dc638068..c104ef75 100644 --- a/inc/Service/Media/GdMediaHandler.php +++ b/inc/Service/Media/GdMediaHandler.php @@ -88,6 +88,25 @@ class GdMediaHandler implements MediaHandler { return null; } + private function installMediaImpl( + mixed $gd, + string $file_path, + string $file_mime, + string $file_kind, + string $preferred_out_file_basepath, + ): string { + $out_path = $preferred_out_file_basepath . '.' . Metadata\mime_to_ext($file_mime); + + if ($this->strip_redraw) { + if (!self::imageSaveTo($gd, $out_path, $file_mime)) { + throw new MediaException("Could not create media file at '$out_path'", MediaException::ERR_IO_ERR); + } + } else { + $this->move_or_link_or_copy($file_kind, $file_path, $out_path); + } + return $out_path; + } + private function generateThumbImpl( mixed $gd, string $source_file_path, @@ -225,6 +244,11 @@ class GdMediaHandler implements MediaHandler { \imagedestroy($handle[0]); } + public function installMedia(mixed $handle, string $preferred_out_file_basepath): string { + list($gd, $file_path, $file_mime, $file_kind) = $handle; + return $this->installMediaImpl($gd, $file_path, $file_mime, $file_kind, $preferred_out_file_basepath); + } + public function installMediaAndGenerateThumb( mixed $handle, string $media_preferred_out_file_basepath, @@ -233,15 +257,13 @@ class GdMediaHandler implements MediaHandler { int $thumb_max_height ): MediaInstallResult { list($gd, $source_file_path, $source_file_mime, $source_file_kind) = $handle; - $out_path = $media_preferred_out_file_basepath . '.' . Metadata\mime_to_ext($source_file_mime); - - if ($this->strip_redraw) { - if (!self::imageSaveTo($gd, $out_path, $source_file_mime)) { - throw new MediaException("Could not create media file at '$out_path'", MediaException::ERR_IO_ERR); - } - } else { - $this->move_or_link_or_copy($source_file_kind, $source_file_path, $out_path); - } + $out_path = $this->installMediaImpl( + $gd, + $source_file_path, + $source_file_mime, + $source_file_kind, + $media_preferred_out_file_basepath + ); $thumb = $this->generateThumbImpl( $gd,