2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-08-16 14:40:42 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-08-16 14:40:42 +00:00
|
|
|
abstract class MediaEngine
|
|
|
|
{
|
|
|
|
public const GD = "gd";
|
|
|
|
public const IMAGICK = "convert";
|
|
|
|
public const FFMPEG = "ffmpeg";
|
2020-01-28 22:23:03 +00:00
|
|
|
public const STATIC = "static";
|
2019-08-16 14:40:42 +00:00
|
|
|
|
2021-12-14 18:32:47 +00:00
|
|
|
public const IMAGE_ENGINES = [
|
2020-06-14 16:36:52 +00:00
|
|
|
"GD" => MediaEngine::GD,
|
|
|
|
"ImageMagick" => MediaEngine::IMAGICK,
|
|
|
|
];
|
|
|
|
|
2019-08-16 14:40:42 +00:00
|
|
|
public const ALL = [
|
|
|
|
MediaEngine::GD,
|
|
|
|
MediaEngine::FFMPEG,
|
2020-01-28 22:23:03 +00:00
|
|
|
MediaEngine::IMAGICK,
|
|
|
|
MediaEngine::STATIC,
|
2019-08-16 14:40:42 +00:00
|
|
|
];
|
2020-06-14 16:05:55 +00:00
|
|
|
private const OUTPUT_SUPPORT = [
|
2019-08-16 14:40:42 +00:00
|
|
|
MediaEngine::GD => [
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::GIF,
|
|
|
|
MimeType::JPEG,
|
|
|
|
MimeType::PNG,
|
|
|
|
MimeType::WEBP
|
2019-08-16 14:40:42 +00:00
|
|
|
],
|
|
|
|
MediaEngine::IMAGICK => [
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::GIF,
|
|
|
|
MimeType::JPEG,
|
|
|
|
MimeType::PNG,
|
|
|
|
MimeType::WEBP,
|
|
|
|
MimeType::WEBP_LOSSLESS,
|
2019-08-16 14:40:42 +00:00
|
|
|
],
|
|
|
|
MediaEngine::FFMPEG => [
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::JPEG,
|
|
|
|
MimeType::WEBP,
|
|
|
|
MimeType::PNG,
|
2020-01-28 22:23:03 +00:00
|
|
|
],
|
|
|
|
MediaEngine::STATIC => [
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::JPEG,
|
2020-01-28 22:23:03 +00:00
|
|
|
],
|
2019-08-16 14:40:42 +00:00
|
|
|
];
|
2020-06-14 16:05:55 +00:00
|
|
|
private const INPUT_SUPPORT = [
|
2019-08-16 14:40:42 +00:00
|
|
|
MediaEngine::GD => [
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::BMP,
|
|
|
|
MimeType::GIF,
|
|
|
|
MimeType::JPEG,
|
|
|
|
MimeType::PNG,
|
2021-01-16 20:18:11 +00:00
|
|
|
MimeType::TGA,
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::WEBP,
|
|
|
|
MimeType::WEBP_LOSSLESS,
|
2019-08-16 14:40:42 +00:00
|
|
|
],
|
|
|
|
MediaEngine::IMAGICK => [
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::BMP,
|
|
|
|
MimeType::GIF,
|
|
|
|
MimeType::JPEG,
|
|
|
|
MimeType::PNG,
|
2020-10-26 12:25:47 +00:00
|
|
|
MimeType::PPM,
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::PSD,
|
2021-01-16 20:18:11 +00:00
|
|
|
MimeType::TGA,
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::TIFF,
|
|
|
|
MimeType::WEBP,
|
|
|
|
MimeType::WEBP_LOSSLESS,
|
|
|
|
MimeType::ICO,
|
2019-08-16 14:40:42 +00:00
|
|
|
],
|
|
|
|
MediaEngine::FFMPEG => [
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::AVI,
|
|
|
|
MimeType::MKV,
|
|
|
|
MimeType::WEBM,
|
|
|
|
MimeType::MP4_VIDEO,
|
|
|
|
MimeType::QUICKTIME,
|
|
|
|
MimeType::FLASH_VIDEO,
|
2020-01-28 22:23:03 +00:00
|
|
|
],
|
|
|
|
MediaEngine::STATIC => [
|
2020-06-14 16:05:55 +00:00
|
|
|
MimeType::JPEG,
|
|
|
|
MimeType::GIF,
|
|
|
|
MimeType::PNG,
|
2020-01-28 22:23:03 +00:00
|
|
|
],
|
2019-08-16 14:40:42 +00:00
|
|
|
];
|
2020-06-11 21:58:19 +00:00
|
|
|
public const RESIZE_TYPE_SUPPORT = [
|
|
|
|
MediaEngine::GD => [
|
|
|
|
Media::RESIZE_TYPE_FIT,
|
|
|
|
Media::RESIZE_TYPE_STRETCH
|
|
|
|
],
|
|
|
|
MediaEngine::IMAGICK => [
|
|
|
|
Media::RESIZE_TYPE_FIT,
|
|
|
|
Media::RESIZE_TYPE_FIT_BLUR,
|
2020-08-28 14:15:45 +00:00
|
|
|
Media::RESIZE_TYPE_FIT_BLUR_PORTRAIT,
|
2020-06-11 21:58:19 +00:00
|
|
|
Media::RESIZE_TYPE_FILL,
|
|
|
|
Media::RESIZE_TYPE_STRETCH,
|
|
|
|
],
|
|
|
|
MediaEngine::FFMPEG => [
|
|
|
|
Media::RESIZE_TYPE_FIT
|
2020-06-23 14:17:54 +00:00
|
|
|
],
|
|
|
|
MediaEngine::STATIC => [
|
|
|
|
Media::RESIZE_TYPE_FIT
|
2020-06-11 21:58:19 +00:00
|
|
|
]
|
|
|
|
];
|
2020-06-14 16:05:55 +00:00
|
|
|
|
|
|
|
public static function is_output_supported(string $engine, string $mime): bool
|
|
|
|
{
|
|
|
|
return MimeType::matches_array(
|
|
|
|
$mime,
|
|
|
|
MediaEngine::OUTPUT_SUPPORT[$engine],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function is_input_supported(string $engine, string $mime): bool
|
|
|
|
{
|
|
|
|
return MimeType::matches_array(
|
|
|
|
$mime,
|
|
|
|
MediaEngine::INPUT_SUPPORT[$engine]
|
|
|
|
);
|
|
|
|
}
|
2019-08-16 14:40:42 +00:00
|
|
|
}
|