LibMagickMediaHandler.php: minor refactor

This commit is contained in:
Zankaria 2025-03-28 14:55:47 +01:00
parent 096a6f04f1
commit f3db700201

View file

@ -351,7 +351,31 @@ class LibMagickMediaHandler implements MediaHandler {
): MediaInstallResult {
list($imagick, $media_file_path, $media_file_mime, $media_file_kind, $width, $height, $orientation) = $handle;
if (!$this->strip_metadata) {
if ($this->strip_metadata) {
self::adjustOrientation($imagick, $orientation);
// Backup the color profile, then re-apply it.
$profiles = $imagick->getImageProfiles('icc', true);
$imagick->stripImage();
if (isset($profiles['icc'])) {
$imagick->profileImage('icc', $profiles['icc']);
}
$out_ext = Metadata\mime_to_ext($media_file_mime);
$out_path = "$media_preferred_out_file_basepath.$out_ext";
$imagick->writeImage("$out_ext:$out_path");
$thumb = self::generateThumbImpl(
$imagick,
$media_file_mime,
$thumb_preferred_out_file_basepath,
$width,
$height,
$thumb_max_width,
$thumb_max_height
);
return new MediaInstallResult($thumb, $out_path);
} else {
$media_out_path = $media_preferred_out_file_basepath . '.' . Metadata\mime_to_ext($media_file_mime);
$this->move_or_link_or_copy($media_file_kind, $media_file_path, $media_out_path);
@ -377,30 +401,6 @@ class LibMagickMediaHandler implements MediaHandler {
);
}
return new MediaInstallResult($thumb, $media_out_path);
} else {
self::adjustOrientation($imagick, $orientation);
// Backup the color profile, then re-apply it.
$profiles = $imagick->getImageProfiles('icc', true);
$imagick->stripImage();
if (!empty($profiles)) {
$imagick->profileImage('icc', $profiles['icc']);
}
$out_ext = Metadata\mime_to_ext($media_file_mime);
$out_path = "$media_preferred_out_file_basepath.$out_ext";
$imagick->writeImage("$out_ext:$out_path");
$thumb = self::generateThumbImpl(
$imagick,
$media_file_mime,
$thumb_preferred_out_file_basepath,
$width,
$height,
$thumb_max_width,
$thumb_max_height
);
return new MediaInstallResult($thumb, $out_path);
}
}
}