forked from leftypol/leftypol
LibMagickMediaHandler.php: implement installMedia
This commit is contained in:
parent
cd3ddfa2c9
commit
a67d81d94f
1 changed files with 29 additions and 6 deletions
|
@ -308,6 +308,30 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$handle[0]->clear();
|
||||
}
|
||||
|
||||
public function installMedia(mixed $handle, string $preferred_out_file_basepath): string {
|
||||
list($imagick, $file_path, $file_mime, $file_kind, $width, $height, $orientation) = $handle;
|
||||
|
||||
$out_ext = Metadata\mime_to_ext($file_mime);
|
||||
$out_path = "$preferred_out_file_basepath.$out_ext";
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
$imagick->writeImage("$out_ext:$out_path");
|
||||
} else {
|
||||
$this->move_or_link_or_copy($file_kind, $file_path, $out_path);
|
||||
}
|
||||
|
||||
return $out_path;
|
||||
}
|
||||
|
||||
public function generateThumb(
|
||||
mixed $handle,
|
||||
string $preferred_out_file_basepath,
|
||||
|
@ -351,6 +375,9 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
): MediaInstallResult {
|
||||
list($imagick, $media_file_path, $media_file_mime, $media_file_kind, $width, $height, $orientation) = $handle;
|
||||
|
||||
$out_ext = Metadata\mime_to_ext($media_file_mime);
|
||||
$media_out_path = "$media_preferred_out_file_basepath.$out_ext";
|
||||
|
||||
if ($this->strip_metadata) {
|
||||
self::adjustOrientation($imagick, $orientation);
|
||||
|
||||
|
@ -361,9 +388,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$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");
|
||||
$imagick->writeImage("$out_ext:$media_out_path");
|
||||
|
||||
$thumb = self::generateThumbImpl(
|
||||
$imagick,
|
||||
|
@ -374,10 +399,8 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$thumb_max_width,
|
||||
$thumb_max_height
|
||||
);
|
||||
return new MediaInstallResult($thumb, $out_path);
|
||||
return new MediaInstallResult($thumb, $media_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);
|
||||
|
||||
if (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue