-
I have a file upload/download API where I am using ImageSharp for downscaling images to create thumbnails of uploaded images (the API supports non-image formats, too). Is there a way I can get a list of the supported file extensions, so that I know which files to process with ImageSharp and which not to? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 17 replies
-
File extensions should never be used as a means to determine a file type. There's nothing stopping anyone putting any extension on any file type which will cause ImageSharp to throw if a file cannot be decoded. Rather, you should use If that returns |
Beta Was this translation helpful? Give feedback.
-
You can get a list of all file extensions (with image decoders) registered against the configured image formats using this: // For simple cases where you are not specifying a custom Configuration
SixLabors.ImageSharp.Configuration config = SixLabors.ImageSharp.Configuration.Default;
// if using IamgeSharp.Web you will want to resolve by getting a refernece to `ImageSharpMiddlewareOptions`
//.from DI and the reading the Configuration property from it.
var allSupportedExtensions = config.ImageFormats
.Where(x=> config.ImageFormatsManager.FindDecoder(x) != null) // we can decode this format (i.e. its not an encode only format)
.SelectMany(x => x.FileExtensions); |
Beta Was this translation helpful? Give feedback.
You can get a list of all file extensions (with image decoders) registered against the configured image formats using this: