forked from leftypol/leftypol
MediaHandler: update
This commit is contained in:
parent
dd788acaf0
commit
573c8e2fb6
4 changed files with 16 additions and 16 deletions
|
@ -2,7 +2,7 @@
|
|||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\{Exif, ImageMetadata};
|
||||
use Vichan\Functions\Mime;
|
||||
use Vichan\Functions\Metadata;
|
||||
|
||||
|
||||
class CmdMagickImageMetadataReader {
|
||||
|
@ -63,7 +63,7 @@ class CmdMagickImageMetadataReader {
|
|||
$ext = $m[3];
|
||||
$orientation_str = $m[4];
|
||||
|
||||
$mime = Mime\ext_to_mime($ext) ?? 'application/octet-stream';
|
||||
$mime = Metadata\ext_to_mime($ext) ?? 'application/octet-stream';
|
||||
$exif_orientation = self::parseOrientation($orientation_str);
|
||||
return new ImageMetadata($width, $height, $mime, $exif_orientation);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\ThumbGenerationResult;
|
||||
use Vichan\Functions\{Fs, Mime};
|
||||
use Vichan\Functions\{Fs, Metadata};
|
||||
|
||||
|
||||
class FallbackMediaHandler implements MediaHandler {
|
||||
|
@ -58,7 +58,7 @@ class FallbackMediaHandler implements MediaHandler {
|
|||
int $thumb_max_height
|
||||
) {
|
||||
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 . '.' . Mime\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);
|
||||
|
||||
if ($source_file_kind === self::FILE_KIND_UPLOADED) {
|
||||
if (!Fs\move_or_copy_uploaded($source_file_path, $out_path)) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\{Exif, ThumbGenerationResult};
|
||||
use Vichan\Functions\{Fs, Mime};
|
||||
use Vichan\Functions\{Fs, Metadata};
|
||||
|
||||
|
||||
/**
|
||||
|
@ -97,7 +97,7 @@ class GdMediaHandler implements MediaHandler {
|
|||
$height = \imagesy($gd);
|
||||
|
||||
if ($width <= $max_width && $height <= $max_height) {
|
||||
$out_path = $preferred_out_file_dir . DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . Mime\mime_to_ext($source_file_mime);
|
||||
$out_path = $preferred_out_file_dir . DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . Metadata\mime_to_ext($source_file_mime);
|
||||
|
||||
if ($source_file_kind === self::FILE_KIND_UPLOADED) {
|
||||
if (!Fs\move_or_copy_uploaded($source_file_path, $out_path)) {
|
||||
|
@ -117,7 +117,7 @@ class GdMediaHandler implements MediaHandler {
|
|||
$height
|
||||
);
|
||||
} else {
|
||||
$out_path = $preferred_out_file_dir . DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . Mime\mime_to_ext($preferred_out_mime);
|
||||
$out_path = $preferred_out_file_dir . DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . Metadata\mime_to_ext($preferred_out_mime);
|
||||
|
||||
$gd_other = self::createCanvas($preferred_out_mime, $max_width, $max_height);
|
||||
\imagecopyresampled($gd_other, $gd, 0, 0, 0, 0, $max_width, $max_height, $width, $height);
|
||||
|
@ -206,7 +206,7 @@ class GdMediaHandler implements MediaHandler {
|
|||
int $thumb_max_height
|
||||
) {
|
||||
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 . '.' . Mime\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);
|
||||
|
||||
if ($this->strip_redraw) {
|
||||
if (!self::imageSaveTo($gd, $out_path, $source_file_mime)) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\ThumbGenerationResult;
|
||||
use Vichan\Functions\{Fs, Mime};
|
||||
use Vichan\Functions\{Fs, Metadata};
|
||||
|
||||
|
||||
class LibMagickMediaHandler implements MediaHandler {
|
||||
|
@ -163,7 +163,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$thumb_height = $height;
|
||||
}
|
||||
|
||||
$out_ext = Mime\mime_to_ext($preferred_out_mime);
|
||||
$out_ext = Metadata\mime_to_ext($preferred_out_mime);
|
||||
$out_path = $preferred_out_file_dir . \DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . $out_ext;
|
||||
|
||||
$imagick->stripImage();
|
||||
|
@ -201,7 +201,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
}
|
||||
|
||||
public function supportsMime(string $mime): bool {
|
||||
$ext = Mime\mime_to_ext($mime);
|
||||
$ext = Metadata\mime_to_ext($mime);
|
||||
if ($ext === null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
}
|
||||
|
||||
public function openHandle(string $file_path, string $file_mime, int $file_kind): mixed {
|
||||
$ext = Mime\mime_to_ext($file_mime);
|
||||
$ext = Metadata\mime_to_ext($file_mime);
|
||||
$path = \realpath($file_path);
|
||||
// Open it as the supplied mime type.
|
||||
$imagick = new \Imagick("$ext:$path");
|
||||
|
@ -237,7 +237,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$height = $imagick->getImageHeight();
|
||||
|
||||
if (!$this->strip_metadata && $width <= $max_width && $height <= $max_height) {
|
||||
$out_path = $preferred_out_file_dir . \DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . Mime\mime_to_ext($source_file_mime);
|
||||
$out_path = $preferred_out_file_dir . \DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . Metadata\mime_to_ext($source_file_mime);
|
||||
|
||||
if ($source_file_kind === self::FILE_KIND_UPLOADED) {
|
||||
if (!Fs\move_or_copy_uploaded($source_file_path, $out_path)) {
|
||||
|
@ -294,7 +294,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$height = $imagick->getImageHeight();
|
||||
|
||||
if (!$this->strip_metadata) {
|
||||
$media_out_path = $media_preferred_out_file_dir . \DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . Mime\mime_to_ext($media_file_mime);
|
||||
$media_out_path = $media_preferred_out_file_dir . \DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . Metadata\mime_to_ext($media_file_mime);
|
||||
|
||||
if ($media_file_kind === self::FILE_KIND_UPLOADED) {
|
||||
if (!Fs\move_or_copy_uploaded($media_file_path, $media_out_path)) {
|
||||
|
@ -307,7 +307,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
}
|
||||
|
||||
if ($width <= $thumb_max_width && $height >= $thumb_max_height) {
|
||||
$thumb_out_path = $thumb_preferred_out_file_dir . \DIRECTORY_SEPARATOR . '.' . Mime\mime_to_ext($media_file_mime);
|
||||
$thumb_out_path = $thumb_preferred_out_file_dir . \DIRECTORY_SEPARATOR . '.' . Metadata\mime_to_ext($media_file_mime);
|
||||
if (!Fs\link_or_copy($media_out_path, $thumb_out_path)) {
|
||||
throw new \RuntimeException("Could not link or copy '$media_out_path' to '$thumb_out_path'");
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ class LibMagickMediaHandler implements MediaHandler {
|
|||
$imagick->profileImage('icc', $profiles['icc']);
|
||||
}
|
||||
|
||||
$out_ext = Mime\mime_to_ext($media_file_mime);
|
||||
$out_ext = Metadata\mime_to_ext($media_file_mime);
|
||||
$out_path = $media_preferred_out_file_dir . \DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . $out_ext;
|
||||
$imagick->writeImage("$out_ext:$out_path");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue