forked from leftypol/leftypol
36 lines
864 B
PHP
36 lines
864 B
PHP
<?php
|
|
namespace Vichan\Functions\Mime;
|
|
|
|
|
|
/**
|
|
* @param string $mime Lowercase valid mime type.
|
|
* @return ?string Vichan's preferred extension for the given mime type, if any.
|
|
*/
|
|
function mime_to_ext(string $mime): ?string {
|
|
static $mime_to_ext = [
|
|
'image/jpeg' => 'jpg',
|
|
'image/png' => 'png',
|
|
'image/gif' => 'gif',
|
|
'image/webp' => 'webp',
|
|
'image/bmp' => 'bmp',
|
|
'image/avif' => 'avif'
|
|
];
|
|
return $mime_to_ext[$mime] ?? null;
|
|
}
|
|
|
|
/**
|
|
* @param string $mime Lowercase extension.
|
|
* @return ?string Vichan's preferred mime type for the given extensions, if any.
|
|
*/
|
|
function ext_to_mime(string $ext): ?string {
|
|
static $ext_to_mime = [
|
|
'jpg' => 'image/jpeg',
|
|
'jpeg' => 'image/jpeg',
|
|
'png' => 'image/png',
|
|
'gif' => 'image/gif',
|
|
'webp' => 'image/webp',
|
|
'bmp' => 'image/bmp',
|
|
'avif' => 'image/avif',
|
|
];
|
|
return $ext_to_mime[$ext] ?? null;
|
|
}
|