forked from leftypol/leftypol
MediaHandler: update
This commit is contained in:
parent
527f6372bb
commit
db3b6984f9
3 changed files with 15 additions and 17 deletions
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\ThumbGenerationResult;
|
||||
use Vichan\Data\{MediaInstallResult, ThumbGenerationResult};
|
||||
use Vichan\Functions\Metadata;
|
||||
|
||||
|
||||
|
@ -58,13 +58,13 @@ class FallbackMediaHandler implements MediaHandler {
|
|||
string $thumb_preferred_out_mime,
|
||||
int $thumb_max_width,
|
||||
int $thumb_max_height
|
||||
) {
|
||||
): MediaInstallResult {
|
||||
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);
|
||||
|
||||
$this->move_or_link_or_copy($source_file_kind, $source_file_path, $out_path);
|
||||
|
||||
return $this->generateThumb(
|
||||
$thumb = $this->generateThumb(
|
||||
$handle,
|
||||
$thumb_preferred_out_file_dir,
|
||||
$thumb_preferred_out_file_name,
|
||||
|
@ -72,6 +72,7 @@ class FallbackMediaHandler implements MediaHandler {
|
|||
$thumb_max_width,
|
||||
$thumb_max_height
|
||||
);
|
||||
return new MediaInstallResult($thumb, $out_path);
|
||||
}
|
||||
|
||||
public function generateThumb(
|
||||
|
@ -85,7 +86,6 @@ class FallbackMediaHandler implements MediaHandler {
|
|||
return new ThumbGenerationResult(
|
||||
$this->path,
|
||||
$this->mime,
|
||||
false,
|
||||
\min($this->width, $max_width),
|
||||
\min($this->height, $max_height)
|
||||
);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\{Exif, ThumbGenerationResult};
|
||||
use Vichan\Data\{Exif, MediaInstallResult, ThumbGenerationResult};
|
||||
use Vichan\Functions\{Fs, Metadata};
|
||||
|
||||
|
||||
|
@ -108,7 +108,6 @@ class GdMediaHandler implements MediaHandler {
|
|||
return new ThumbGenerationResult(
|
||||
$out_path,
|
||||
$source_file_mime,
|
||||
false,
|
||||
$width,
|
||||
$height
|
||||
);
|
||||
|
@ -128,7 +127,6 @@ class GdMediaHandler implements MediaHandler {
|
|||
return new ThumbGenerationResult(
|
||||
$out_path,
|
||||
$preferred_out_mime,
|
||||
false,
|
||||
$max_width,
|
||||
$max_height
|
||||
);
|
||||
|
@ -214,7 +212,7 @@ class GdMediaHandler implements MediaHandler {
|
|||
string $thumb_preferred_out_mime,
|
||||
int $thumb_max_width,
|
||||
int $thumb_max_height
|
||||
) {
|
||||
): MediaInstallResult {
|
||||
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);
|
||||
|
||||
|
@ -226,7 +224,7 @@ class GdMediaHandler implements MediaHandler {
|
|||
$this->move_or_link_or_copy($source_file_kind, $source_file_path, $out_path);
|
||||
}
|
||||
|
||||
return $this->generateThumbImpl(
|
||||
$thumb = $this->generateThumbImpl(
|
||||
$gd,
|
||||
$source_file_path,
|
||||
$source_file_mime,
|
||||
|
@ -237,6 +235,7 @@ class GdMediaHandler implements MediaHandler {
|
|||
$thumb_max_width,
|
||||
$thumb_max_height
|
||||
);
|
||||
return new MediaInstallResult($thumb, $out_path);
|
||||
}
|
||||
|
||||
public function generateThumb(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\ThumbGenerationResult;
|
||||
use Vichan\Data\{MediaInstallResult, ThumbGenerationResult};
|
||||
use Vichan\Functions\{Fs, Metadata};
|
||||
|
||||
|
||||
|
@ -151,7 +151,6 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
return new ThumbGenerationResult(
|
||||
$out_path,
|
||||
'image/gif',
|
||||
false,
|
||||
$thumb_width,
|
||||
$thumb_height
|
||||
);
|
||||
|
@ -177,7 +176,6 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
return new ThumbGenerationResult(
|
||||
$out_path,
|
||||
$preferred_out_mime,
|
||||
false,
|
||||
$thumb_width,
|
||||
$thumb_height
|
||||
);
|
||||
|
@ -258,7 +256,6 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
return new ThumbGenerationResult(
|
||||
$out_path,
|
||||
$source_file_mime,
|
||||
false,
|
||||
$max_width,
|
||||
$max_height
|
||||
);
|
||||
|
@ -293,7 +290,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
string $thumb_preferred_out_mime,
|
||||
int $thumb_max_width,
|
||||
int $thumb_max_height
|
||||
): ThumbGenerationResult {
|
||||
): MediaInstallResult {
|
||||
list($imagick, $media_file_path, $media_file_mime, $media_file_kind) = $handle;
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
return new ThumbGenerationResult($thumb_out_path, $media_file_mime, false, $width, $height);
|
||||
$thumb = new ThumbGenerationResult($thumb_out_path, $media_file_mime, $width, $height);
|
||||
} else {
|
||||
$swap = self::adjustOrientation($imagick);
|
||||
if ($swap) {
|
||||
|
@ -319,7 +316,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$height = $tmp;
|
||||
}
|
||||
|
||||
return self::generateThumbImpl(
|
||||
$thumb = self::generateThumbImpl(
|
||||
$imagick,
|
||||
$media_file_mime,
|
||||
$thumb_preferred_out_file_dir,
|
||||
|
@ -331,6 +328,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$thumb_max_height
|
||||
);
|
||||
}
|
||||
return new MediaInstallResult($thumb, $media_out_path);
|
||||
} else {
|
||||
$swap = self::adjustOrientation($imagick);
|
||||
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;
|
||||
$imagick->writeImage("$out_ext:$out_path");
|
||||
|
||||
return self::generateThumbImpl(
|
||||
$thumb = self::generateThumbImpl(
|
||||
$imagick,
|
||||
$media_file_mime,
|
||||
$thumb_preferred_out_file_dir,
|
||||
|
@ -361,6 +359,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$thumb_max_width,
|
||||
$thumb_max_height
|
||||
);
|
||||
return new MediaInstallResult($thumb, $out_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue