GdMediaHandler.php: update

This commit is contained in:
Zankaria 2025-03-28 12:48:01 +01:00
parent 19a3f6fa8f
commit 2c55c4fa23

View file

@ -19,6 +19,7 @@ class GdMediaHandler implements MediaHandler {
private array $exif_readers; private array $exif_readers;
private int $image_max_width; private int $image_max_width;
private int $image_max_height; private int $image_max_height;
private string $thumb_mime;
private static function imageCreateFrom(string $file, string $mime): mixed { private static function imageCreateFrom(string $file, string $mime): mixed {
@ -93,7 +94,6 @@ class GdMediaHandler implements MediaHandler {
string $source_file_mime, string $source_file_mime,
string $source_file_kind, string $source_file_kind,
string $preferred_out_file_basepath, string $preferred_out_file_basepath,
string $preferred_out_mime,
int $max_width, int $max_width,
int $max_height int $max_height
) { ) {
@ -112,12 +112,12 @@ class GdMediaHandler implements MediaHandler {
$height $height
); );
} else { } else {
$out_path = $preferred_out_file_basepath . '.' . Metadata\mime_to_ext($preferred_out_mime); $out_path = $preferred_out_file_basepath . '.' . Metadata\mime_to_ext($this->thumb_mime);
$gd_other = self::createCanvas($preferred_out_mime, $max_width, $max_height); $gd_other = self::createCanvas($this->thumb_mime, $max_width, $max_height);
\imagecopyresampled($gd_other, $gd, 0, 0, 0, 0, $max_width, $max_height, $width, $height); \imagecopyresampled($gd_other, $gd, 0, 0, 0, 0, $max_width, $max_height, $width, $height);
if (!self::imageSaveTo($gd_other, $out_path, $preferred_out_mime)) { if (!self::imageSaveTo($gd_other, $out_path, $this->thumb_mime)) {
\imagedestroy($gd_other); \imagedestroy($gd_other);
throw new MediaException("Could not create thumbnail file at '$out_path'", MediaException::ERR_IO_ERR); throw new MediaException("Could not create thumbnail file at '$out_path'", MediaException::ERR_IO_ERR);
} }
@ -126,7 +126,7 @@ class GdMediaHandler implements MediaHandler {
return new ThumbGenerationResult( return new ThumbGenerationResult(
$out_path, $out_path,
$preferred_out_mime, $this->thumb_mime,
$max_width, $max_width,
$max_height $max_height
); );
@ -138,11 +138,12 @@ class GdMediaHandler implements MediaHandler {
* May cause the loss of color profiles. Orientation is still handled in JPG and PNG. * May cause the loss of color profiles. Orientation is still handled in JPG and PNG.
* @param array $exif_readers A map of mime types to {@link Vichan\Data\Driver\Metadata\ExifReader} instances. * @param array $exif_readers A map of mime types to {@link Vichan\Data\Driver\Metadata\ExifReader} instances.
*/ */
public function __construct(bool $strip_redraw, array $exif_readers, int $max_width, int $max_height) { public function __construct(bool $strip_redraw, array $exif_readers, int $max_width, int $max_height, string $thumb_mime) {
$this->strip_redraw = $strip_redraw; $this->strip_redraw = $strip_redraw;
$this->exif_readers = $exif_readers; $this->exif_readers = $exif_readers;
$this->image_max_width = $max_width; $this->image_max_width = $max_width;
$this->image_max_height = $max_height; $this->image_max_height = $max_height;
$this->thumb_mime = $thumb_mime;
} }
public function supportsMime(string $mime): bool { public function supportsMime(string $mime): bool {
@ -228,7 +229,6 @@ class GdMediaHandler implements MediaHandler {
mixed $handle, mixed $handle,
string $media_preferred_out_file_basepath, string $media_preferred_out_file_basepath,
string $thumb_preferred_out_file_basepath, string $thumb_preferred_out_file_basepath,
string $thumb_preferred_out_mime,
int $thumb_max_width, int $thumb_max_width,
int $thumb_max_height int $thumb_max_height
): MediaInstallResult { ): MediaInstallResult {
@ -249,7 +249,6 @@ class GdMediaHandler implements MediaHandler {
$source_file_mime, $source_file_mime,
$source_file_kind, $source_file_kind,
$thumb_preferred_out_file_basepath, $thumb_preferred_out_file_basepath,
$thumb_preferred_out_mime,
$thumb_max_width, $thumb_max_width,
$thumb_max_height $thumb_max_height
); );
@ -259,7 +258,6 @@ class GdMediaHandler implements MediaHandler {
public function generateThumb( public function generateThumb(
mixed $handle, mixed $handle,
string $preferred_out_file_basepath, string $preferred_out_file_basepath,
string $preferred_out_mime,
int $max_width, int $max_width,
int $max_height int $max_height
): ThumbGenerationResult { ): ThumbGenerationResult {
@ -271,7 +269,6 @@ class GdMediaHandler implements MediaHandler {
$source_file_mime, $source_file_mime,
$source_file_kind, $source_file_kind,
$preferred_out_file_basepath, $preferred_out_file_basepath,
$preferred_out_mime,
$max_width, $max_width,
$max_height $max_height
); );