This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/media/media_engine.php

122 lines
3 KiB
PHP
Raw Normal View History

2021-12-14 18:32:47 +00:00
<?php
declare(strict_types=1);
2019-08-16 14:40:42 +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";
public const STATIC = "static";
2019-08-16 14:40:42 +00:00
2021-12-14 18:32:47 +00:00
public const IMAGE_ENGINES = [
"GD" => MediaEngine::GD,
"ImageMagick" => MediaEngine::IMAGICK,
];
2019-08-16 14:40:42 +00:00
public const ALL = [
MediaEngine::GD,
MediaEngine::FFMPEG,
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,
],
MediaEngine::STATIC => [
2020-06-14 16:05:55 +00:00
MimeType::JPEG,
],
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,
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,
],
MediaEngine::STATIC => [
2020-06-14 16:05:55 +00:00
MimeType::JPEG,
MimeType::GIF,
MimeType::PNG,
],
2019-08-16 14:40:42 +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,
Media::RESIZE_TYPE_FIT_BLUR_PORTRAIT,
Media::RESIZE_TYPE_FILL,
Media::RESIZE_TYPE_STRETCH,
],
MediaEngine::FFMPEG => [
Media::RESIZE_TYPE_FIT
],
MediaEngine::STATIC => [
Media::RESIZE_TYPE_FIT
]
];
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
}