Browse Source

Allow leading period in FindFormatByFileExtension

af/merge-core
Jason Nelson 8 years ago
parent
commit
00a0451e21
  1. 7
      src/ImageSharp/Formats/ImageFormatManager.cs
  2. 2
      src/ImageSharp/ImageExtensions.cs
  3. 4
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs

7
src/ImageSharp/Formats/ImageFormatManager.cs

@ -85,6 +85,13 @@ namespace SixLabors.ImageSharp.Formats
/// <returns>The <see cref="IImageFormat"/> if found otherwise null</returns>
public IImageFormat FindFormatByFileExtension(string extension)
{
Guard.NotNullOrWhiteSpace(extension, nameof(extension));
if (extension[0] == '.')
{
extension = extension.Substring(1);
}
return this.imageFormats.FirstOrDefault(x => x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase));
}

2
src/ImageSharp/ImageExtensions.cs

@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp
{
Guard.NotNullOrWhiteSpace(filePath, nameof(filePath));
string ext = Path.GetExtension(filePath).Trim('.');
string ext = Path.GetExtension(filePath);
IImageFormat format = source.GetConfiguration().ImageFormatsManager.FindFormatByFileExtension(ext);
if (format == null)
{

4
tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs

@ -32,8 +32,8 @@ namespace SixLabors.ImageSharp.Tests
internal static IImageFormat GetImageFormat(string filePath)
{
string extension = Path.GetExtension(filePath).ToLower();
if (extension[0] == '.') extension = extension.Substring(1);
string extension = Path.GetExtension(filePath);
IImageFormat format = Configuration.ImageFormatsManager.FindFormatByFileExtension(extension);
return format;
}

Loading…
Cancel
Save