question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Proposal: method to retrieve ImagePartType from file extension

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tomjebocommented, Nov 29, 2021

@JaimeStill That looks very doable, please feel free to submit a PR and we can iterate on it if needed.

1reaction
rmboggscommented, Nov 28, 2021

I think this is a good idea. I’m not sure where this would fit in this project though.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found