| | 1 | | using System.ComponentModel; |
| | 2 | | using System.Net.Mime; |
| | 3 | |
|
| | 4 | | namespace MediaBrowser.Model.Drawing; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Extension class for the <see cref="ImageFormat" /> enum. |
| | 8 | | /// </summary> |
| | 9 | | public static class ImageFormatExtensions |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Returns the correct mime type for this <see cref="ImageFormat" />. |
| | 13 | | /// </summary> |
| | 14 | | /// <param name="format">This <see cref="ImageFormat" />.</param> |
| | 15 | | /// <exception cref="InvalidEnumArgumentException">The <paramref name="format"/> is an invalid enumeration value.</e |
| | 16 | | /// <returns>The correct mime type for this <see cref="ImageFormat" />.</returns> |
| | 17 | | public static string GetMimeType(this ImageFormat format) |
| 12 | 18 | | => format switch |
| 12 | 19 | | { |
| 1 | 20 | | ImageFormat.Bmp => MediaTypeNames.Image.Bmp, |
| 1 | 21 | | ImageFormat.Gif => MediaTypeNames.Image.Gif, |
| 3 | 22 | | ImageFormat.Jpg => MediaTypeNames.Image.Jpeg, |
| 1 | 23 | | ImageFormat.Png => MediaTypeNames.Image.Png, |
| 1 | 24 | | ImageFormat.Webp => MediaTypeNames.Image.Webp, |
| 1 | 25 | | ImageFormat.Svg => MediaTypeNames.Image.Svg, |
| 4 | 26 | | _ => throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(ImageFormat)) |
| 12 | 27 | | }; |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Returns the correct extension for this <see cref="ImageFormat" />. |
| | 31 | | /// </summary> |
| | 32 | | /// <param name="format">This <see cref="ImageFormat" />.</param> |
| | 33 | | /// <exception cref="InvalidEnumArgumentException">The <paramref name="format"/> is an invalid enumeration value.</e |
| | 34 | | /// <returns>The correct extension for this <see cref="ImageFormat" />.</returns> |
| | 35 | | public static string GetExtension(this ImageFormat format) |
| 10 | 36 | | => format switch |
| 10 | 37 | | { |
| 1 | 38 | | ImageFormat.Bmp => ".bmp", |
| 1 | 39 | | ImageFormat.Gif => ".gif", |
| 1 | 40 | | ImageFormat.Jpg => ".jpg", |
| 1 | 41 | | ImageFormat.Png => ".png", |
| 1 | 42 | | ImageFormat.Webp => ".webp", |
| 1 | 43 | | ImageFormat.Svg => ".svg", |
| 4 | 44 | | _ => throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(ImageFormat)) |
| 10 | 45 | | }; |
| | 46 | | } |