From 97ca3cca4fe824a8143008957d908e190be851c0 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Thu, 20 Mar 2025 17:31:43 +0100 Subject: [PATCH] mime.php: add mime functions --- inc/functions/mime.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 inc/functions/mime.php 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; +}