diff --git a/inc/functions/mime.php b/inc/functions/mime.php new file mode 100644 index 00000000..233beec8 --- /dev/null +++ b/inc/functions/mime.php @@ -0,0 +1,36 @@ + '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; +}