Skip to content

Commit

Permalink
add extension method to resolve issue dotnet#1488
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeebowen committed Jul 19, 2023
1 parent 6463a51 commit 242263a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/DocumentFormat.OpenXml/Packaging/ImagePartExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public static class ImagePartExtensions
/// <summary>
/// Extends an overloaded AddImagePart method that
/// handles the process of determining the ImagePartType
/// for you based on a provided file extension.
/// for you based on a provided file extension or mime type.
/// </summary>
/// <param name="main">The source MainDocumentPart that is adding the ImagePart.</param>
/// <param name="extension">The file extension of the image.</param>
/// <param name="extension">The file extension or mime type of the image.</param>
/// <see cref="MainDocumentPart.AddImagePart(ImagePartType)" />
public static ImagePart AddImagePart(this MainDocumentPart main, string extension) =>
main.AddImagePart(ImagePartTypeInfo.GetImagePartType(extension));
Expand Down
10 changes: 10 additions & 0 deletions src/DocumentFormat.OpenXml/Packaging/ImagePartTypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ internal static ImagePartType GetImagePartType(string extension)
".svg" => ImagePartType.Svg,
".tiff" => ImagePartType.Tiff,
".wmf" => ImagePartType.Wmf,
"image/bmp" => ImagePartType.Bmp,
"image/gif" => ImagePartType.Gif,
"image/png" => ImagePartType.Png,
"image/tiff" => ImagePartType.Tiff,
"image/x-icon" => ImagePartType.Icon,
"image/x-pcx" => ImagePartType.Pcx,
"image/jpeg" => ImagePartType.Jpeg,
"image/x-emf" => ImagePartType.Emf,
"image/x-wmf" => ImagePartType.Wmf,
"image/svg+xml" => ImagePartType.Svg,
_ => throw new NotSupportedException($"{extension} is not supported"),
};
}
Expand Down

0 comments on commit 242263a

Please sign in to comment.