GdMediaHandler.php: implement installMedia

This commit is contained in:
Zankaria 2025-03-28 23:27:52 +01:00
parent 969543ae5f
commit db3b59e018

View file

@ -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,