forked from leftypol/leftypol
metadata.php: rename from mime.php
This commit is contained in:
parent
f881265ce3
commit
dd788acaf0
2 changed files with 46 additions and 1 deletions
36
inc/functions/metadata.php
Normal file
36
inc/functions/metadata.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
namespace Vichan\Functions\Metadata;
|
||||
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue