Feature Proposal: method to retrieve ImagePartType from file extension
See original GitHub issueDescription
In working through some abstractions for working with images in wordprocessing documents, I wrote a method for getting the ImagePartType
based on the provided extension. I’m trying to see the utility of incorporating this into the API, and if so, where I might incorporate it?
// proposed method
static ImagePartType GetImagePartType(string ext) =>
ext.ToLower() switch
{
".bmp" => ImagePartType.Bmp,
".emf" => ImagePartType.Emf,
".ico" => ImagePartType.Icon,
".jpg" => ImagePartType.Jpeg,
".jpeg" => ImagePartType.Jpeg,
".pcx" => ImagePartType.Pcx,
".png" => ImagePartType.Png,
".svg" => ImagePartType.Svg,
".tiff" => ImagePartType.Tiff,
".wmf" => ImagePartType.Wmf,
_ => throw new NotSupportedException($"{ext} is not supported")
};
// example usage
static ImagePart LoadImageIntoDoc(MainDocumentPart main, FileInfo file)
{
var imagePart = main.AddImagePart(GetImagePartType(file.Extension));
// remaining method excluded for brevity
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
New ImagePart is created as .bin instead of real extension
If I create a new ImagePart with the SDK and feed it data like this: ImagePart new_ImagePart = worksheetPart.AddImagePart(ImagePartType.Tiff); ...
Read more >Is there an expectable function to find out what type an ...
The only way to know for sure is to read the actual bitmap file and see what format it is in. You can...
Read more >ImagePartType Enum (DocumentFormat.OpenXml. ...
Defines ImagePartType - types of ImagePart.
Read more >DocumentFormat.OpenXml 2.20.0
Retrieving metrics from DOCX files, including the hierarchy of styles used, the languages used, and the fonts used. ... Writing XLSX files using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@JaimeStill That looks very doable, please feel free to submit a PR and we can iterate on it if needed.
I think this is a good idea. I’m not sure where this would fit in this project though.