mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-28 06:35:01 +00:00
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
OpenAPI / OpenAPI - HEAD (push) Waiting to run
OpenAPI / OpenAPI - BASE (push) Waiting to run
OpenAPI / OpenAPI - Difference (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Unstable Spec (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Stable Spec (push) Blocked by required conditions
Tests / run-tests (macos-latest) (push) Waiting to run
Tests / run-tests (ubuntu-latest) (push) Waiting to run
Tests / run-tests (windows-latest) (push) Waiting to run
Project Automation / Project board (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
47 lines
2.0 KiB
C#
47 lines
2.0 KiB
C#
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 => MediaTypeNames.Image.Bmp,
|
|
ImageFormat.Gif => MediaTypeNames.Image.Gif,
|
|
ImageFormat.Jpg => MediaTypeNames.Image.Jpeg,
|
|
ImageFormat.Png => MediaTypeNames.Image.Png,
|
|
ImageFormat.Webp => MediaTypeNames.Image.Webp,
|
|
ImageFormat.Svg => MediaTypeNames.Image.Svg,
|
|
_ => throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(ImageFormat))
|
|
};
|
|
|
|
/// <summary>
|
|
/// Returns the correct extension 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 extension for this <see cref="ImageFormat" />.</returns>
|
|
public static string GetExtension(this ImageFormat format)
|
|
=> format switch
|
|
{
|
|
ImageFormat.Bmp => ".bmp",
|
|
ImageFormat.Gif => ".gif",
|
|
ImageFormat.Jpg => ".jpg",
|
|
ImageFormat.Png => ".png",
|
|
ImageFormat.Webp => ".webp",
|
|
ImageFormat.Svg => ".svg",
|
|
_ => throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(ImageFormat))
|
|
};
|
|
}
|