MediaHandler: update

This commit is contained in:
Zankaria 2025-03-26 00:36:04 +01:00
parent 527f6372bb
commit db3b6984f9
3 changed files with 15 additions and 17 deletions

View file

@ -1,7 +1,7 @@
<?php <?php
namespace Vichan\Service\Media; namespace Vichan\Service\Media;
use Vichan\Data\ThumbGenerationResult; use Vichan\Data\{MediaInstallResult, ThumbGenerationResult};
use Vichan\Functions\Metadata; use Vichan\Functions\Metadata;
@ -58,13 +58,13 @@ class FallbackMediaHandler implements MediaHandler {
string $thumb_preferred_out_mime, string $thumb_preferred_out_mime,
int $thumb_max_width, int $thumb_max_width,
int $thumb_max_height int $thumb_max_height
) { ): MediaInstallResult {
list($source_file_path, $source_file_mime, $source_file_kind) = $handle; list($source_file_path, $source_file_mime, $source_file_kind) = $handle;
$out_path = $media_preferred_out_file_dir . DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . Metadata\mime_to_ext($source_file_mime); $out_path = $media_preferred_out_file_dir . DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . Metadata\mime_to_ext($source_file_mime);
$this->move_or_link_or_copy($source_file_kind, $source_file_path, $out_path); $this->move_or_link_or_copy($source_file_kind, $source_file_path, $out_path);
return $this->generateThumb( $thumb = $this->generateThumb(
$handle, $handle,
$thumb_preferred_out_file_dir, $thumb_preferred_out_file_dir,
$thumb_preferred_out_file_name, $thumb_preferred_out_file_name,
@ -72,6 +72,7 @@ class FallbackMediaHandler implements MediaHandler {
$thumb_max_width, $thumb_max_width,
$thumb_max_height $thumb_max_height
); );
return new MediaInstallResult($thumb, $out_path);
} }
public function generateThumb( public function generateThumb(
@ -85,7 +86,6 @@ class FallbackMediaHandler implements MediaHandler {
return new ThumbGenerationResult( return new ThumbGenerationResult(
$this->path, $this->path,
$this->mime, $this->mime,
false,
\min($this->width, $max_width), \min($this->width, $max_width),
\min($this->height, $max_height) \min($this->height, $max_height)
); );

View file

@ -1,7 +1,7 @@
<?php <?php
namespace Vichan\Service\Media; namespace Vichan\Service\Media;
use Vichan\Data\{Exif, ThumbGenerationResult}; use Vichan\Data\{Exif, MediaInstallResult, ThumbGenerationResult};
use Vichan\Functions\{Fs, Metadata}; use Vichan\Functions\{Fs, Metadata};
@ -108,7 +108,6 @@ class GdMediaHandler implements MediaHandler {
return new ThumbGenerationResult( return new ThumbGenerationResult(
$out_path, $out_path,
$source_file_mime, $source_file_mime,
false,
$width, $width,
$height $height
); );
@ -128,7 +127,6 @@ class GdMediaHandler implements MediaHandler {
return new ThumbGenerationResult( return new ThumbGenerationResult(
$out_path, $out_path,
$preferred_out_mime, $preferred_out_mime,
false,
$max_width, $max_width,
$max_height $max_height
); );
@ -214,7 +212,7 @@ class GdMediaHandler implements MediaHandler {
string $thumb_preferred_out_mime, string $thumb_preferred_out_mime,
int $thumb_max_width, int $thumb_max_width,
int $thumb_max_height int $thumb_max_height
) { ): MediaInstallResult {
list($gd, $source_file_path, $source_file_mime, $source_file_kind) = $handle; list($gd, $source_file_path, $source_file_mime, $source_file_kind) = $handle;
$out_path = $media_preferred_out_file_dir . DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . Metadata\mime_to_ext($source_file_mime); $out_path = $media_preferred_out_file_dir . DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . Metadata\mime_to_ext($source_file_mime);
@ -226,7 +224,7 @@ class GdMediaHandler implements MediaHandler {
$this->move_or_link_or_copy($source_file_kind, $source_file_path, $out_path); $this->move_or_link_or_copy($source_file_kind, $source_file_path, $out_path);
} }
return $this->generateThumbImpl( $thumb = $this->generateThumbImpl(
$gd, $gd,
$source_file_path, $source_file_path,
$source_file_mime, $source_file_mime,
@ -237,6 +235,7 @@ class GdMediaHandler implements MediaHandler {
$thumb_max_width, $thumb_max_width,
$thumb_max_height $thumb_max_height
); );
return new MediaInstallResult($thumb, $out_path);
} }
public function generateThumb( public function generateThumb(

View file

@ -1,7 +1,7 @@
<?php <?php
namespace Vichan\Service\Media; namespace Vichan\Service\Media;
use Vichan\Data\ThumbGenerationResult; use Vichan\Data\{MediaInstallResult, ThumbGenerationResult};
use Vichan\Functions\{Fs, Metadata}; use Vichan\Functions\{Fs, Metadata};
@ -151,7 +151,6 @@ class LibMagickMediaHandler implements MediaHandler {
return new ThumbGenerationResult( return new ThumbGenerationResult(
$out_path, $out_path,
'image/gif', 'image/gif',
false,
$thumb_width, $thumb_width,
$thumb_height $thumb_height
); );
@ -177,7 +176,6 @@ class LibMagickMediaHandler implements MediaHandler {
return new ThumbGenerationResult( return new ThumbGenerationResult(
$out_path, $out_path,
$preferred_out_mime, $preferred_out_mime,
false,
$thumb_width, $thumb_width,
$thumb_height $thumb_height
); );
@ -258,7 +256,6 @@ class LibMagickMediaHandler implements MediaHandler {
return new ThumbGenerationResult( return new ThumbGenerationResult(
$out_path, $out_path,
$source_file_mime, $source_file_mime,
false,
$max_width, $max_width,
$max_height $max_height
); );
@ -293,7 +290,7 @@ class LibMagickMediaHandler implements MediaHandler {
string $thumb_preferred_out_mime, string $thumb_preferred_out_mime,
int $thumb_max_width, int $thumb_max_width,
int $thumb_max_height int $thumb_max_height
): ThumbGenerationResult { ): MediaInstallResult {
list($imagick, $media_file_path, $media_file_mime, $media_file_kind) = $handle; list($imagick, $media_file_path, $media_file_mime, $media_file_kind) = $handle;
$width = $imagick->getImageWidth(); $width = $imagick->getImageWidth();
@ -310,7 +307,7 @@ class LibMagickMediaHandler implements MediaHandler {
throw new MediaException("Could not link or copy '$media_out_path' to '$thumb_out_path'", MediaException::ERR_IO_ERR); throw new MediaException("Could not link or copy '$media_out_path' to '$thumb_out_path'", MediaException::ERR_IO_ERR);
} }
return new ThumbGenerationResult($thumb_out_path, $media_file_mime, false, $width, $height); $thumb = new ThumbGenerationResult($thumb_out_path, $media_file_mime, $width, $height);
} else { } else {
$swap = self::adjustOrientation($imagick); $swap = self::adjustOrientation($imagick);
if ($swap) { if ($swap) {
@ -319,7 +316,7 @@ class LibMagickMediaHandler implements MediaHandler {
$height = $tmp; $height = $tmp;
} }
return self::generateThumbImpl( $thumb = self::generateThumbImpl(
$imagick, $imagick,
$media_file_mime, $media_file_mime,
$thumb_preferred_out_file_dir, $thumb_preferred_out_file_dir,
@ -331,6 +328,7 @@ class LibMagickMediaHandler implements MediaHandler {
$thumb_max_height $thumb_max_height
); );
} }
return new MediaInstallResult($thumb, $media_out_path);
} else { } else {
$swap = self::adjustOrientation($imagick); $swap = self::adjustOrientation($imagick);
if ($swap) { if ($swap) {
@ -350,7 +348,7 @@ class LibMagickMediaHandler implements MediaHandler {
$out_path = $media_preferred_out_file_dir . \DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . $out_ext; $out_path = $media_preferred_out_file_dir . \DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . $out_ext;
$imagick->writeImage("$out_ext:$out_path"); $imagick->writeImage("$out_ext:$out_path");
return self::generateThumbImpl( $thumb = self::generateThumbImpl(
$imagick, $imagick,
$media_file_mime, $media_file_mime,
$thumb_preferred_out_file_dir, $thumb_preferred_out_file_dir,
@ -361,6 +359,7 @@ class LibMagickMediaHandler implements MediaHandler {
$thumb_max_width, $thumb_max_width,
$thumb_max_height $thumb_max_height
); );
return new MediaInstallResult($thumb, $out_path);
} }
} }
} }