forked from leftypol/leftypol
GdMediaHandler.php: use mime functions
This commit is contained in:
parent
faf754afed
commit
c5c8966d19
1 changed files with 4 additions and 13 deletions
|
@ -2,7 +2,7 @@
|
|||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\ThumbGenerationResult;
|
||||
use Vichan\Functions\Fs;
|
||||
use Vichan\Functions\{Fs, Mime};
|
||||
|
||||
|
||||
/**
|
||||
|
@ -11,15 +11,6 @@ use Vichan\Functions\Fs;
|
|||
class GdMediaHandler implements MediaHandler {
|
||||
private const PHP81 = \PHP_MAJOR_VERSION >= 8 && \PHP_MINOR_VERSION >= 1;
|
||||
|
||||
private const MIME_TO_EXT = [
|
||||
'image/jpeg' => 'jpg',
|
||||
'image/png' => 'png',
|
||||
'image/gif' => 'gif',
|
||||
'image/webp' => 'webp',
|
||||
'image/bmp' => 'bmp',
|
||||
'image/avif' => 'avif'
|
||||
];
|
||||
|
||||
|
||||
private bool $strip_redraw;
|
||||
|
||||
|
@ -93,7 +84,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 . '.' . self::MIME_TO_EXT[$source_file_mime];
|
||||
$out_path = $preferred_out_file_dir . DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . Mime\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)) {
|
||||
|
@ -113,7 +104,7 @@ class GdMediaHandler implements MediaHandler {
|
|||
$height
|
||||
);
|
||||
} else {
|
||||
$out_path = $preferred_out_file_dir . DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . self::MIME_TO_EXT[$preferred_out_mime];
|
||||
$out_path = $preferred_out_file_dir . DIRECTORY_SEPARATOR . $preferred_out_file_name . '.' . Mime\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);
|
||||
|
@ -176,7 +167,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 . '.' . self::MIME_TO_EXT[$source_file_mime];
|
||||
$out_path = $media_preferred_out_file_dir . DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . Mime\mime_to_ext($source_file_mime);
|
||||
|
||||
if ($this->strip_redraw) {
|
||||
if (!self::imageSaveTo($gd, $out_path, $source_file_mime)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue