diff options
| author | Cody Robibero <cody@robibe.ro> | 2022-01-08 04:45:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-08 04:45:58 -0700 |
| commit | 9b1965b48ace52d325aeedf31932a860ffadea3f (patch) | |
| tree | 846e5d2ca77b7a8a764e9afaa5be610885126cc2 /MediaBrowser.Model/Drawing/ImageFormatExtensions.cs | |
| parent | ce61dff4aae0875cfc359c9d8dc1a8a15f9409cd (diff) | |
| parent | dc222b75c55645fce521c572acebb16b278169a5 (diff) | |
Merge pull request #7101 from Bond-009/imagejpg
Remove incorrect mime type image/jpg
Diffstat (limited to 'MediaBrowser.Model/Drawing/ImageFormatExtensions.cs')
| -rw-r--r-- | MediaBrowser.Model/Drawing/ImageFormatExtensions.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/MediaBrowser.Model/Drawing/ImageFormatExtensions.cs b/MediaBrowser.Model/Drawing/ImageFormatExtensions.cs new file mode 100644 index 000000000..68a5c2534 --- /dev/null +++ b/MediaBrowser.Model/Drawing/ImageFormatExtensions.cs @@ -0,0 +1,27 @@ +using System.ComponentModel; +using System.Net.Mime; + +namespace MediaBrowser.Model.Drawing; + +/// <summary> +/// Extension class for the <see cref="ImageFormat" /> enum. +/// </summary> +public static class ImageFormatExtensions +{ + /// <summary> + /// Returns the correct mime type for this <see cref="ImageFormat" />. + /// </summary> + /// <param name="format">This <see cref="ImageFormat" />.</param> + /// <exception cref="InvalidEnumArgumentException">The <paramref name="format"/> is an invalid enumeration value.</exception> + /// <returns>The correct mime type for this <see cref="ImageFormat" />.</returns> + public static string GetMimeType(this ImageFormat format) + => format switch + { + ImageFormat.Bmp => "image/bmp", + ImageFormat.Gif => MediaTypeNames.Image.Gif, + ImageFormat.Jpg => MediaTypeNames.Image.Jpeg, + ImageFormat.Png => "image/png", + ImageFormat.Webp => "image/webp", + _ => throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(ImageFormat)) + }; +} |
