diff options
| author | oledfish <88390729+oledfish@users.noreply.github.com> | 2022-01-16 21:33:18 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-16 21:33:18 -0300 |
| commit | 3b075a58027be4a2a3bdf662c70934f6cafafe87 (patch) | |
| tree | b4c226f25f843c3f2685c92e1edc3b3999716d34 /MediaBrowser.Model/Drawing/ImageFormatExtensions.cs | |
| parent | 86a5e72a65df638df2cde349ccd2ad8c5d40f88c (diff) | |
| parent | ef0708d876434a99ec647473c37295fab45a35fb (diff) | |
Merge branch 'jellyfin:master' into additional-episode-orders
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)) + }; +} |
