diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index 3237ea743..a078f2db9 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Threading.Tasks; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; @@ -89,6 +90,17 @@ namespace SixLabors.ImageSharp public static Image Load(string path) => Load(Configuration.Default, path); + /// + /// Create a new instance of the class from the given file. + /// + /// The file path to the image. + /// + /// Thrown if the stream is not readable nor seekable. + /// + /// A representing the asynchronous operation. + public static Task LoadAsync(string path) + => LoadAsync(Configuration.Default, path); + /// /// Create a new instance of the class from the given file. /// @@ -114,6 +126,25 @@ namespace SixLabors.ImageSharp public static Image Load(Configuration configuration, string path) => Load(configuration, path, out _); + /// + /// Create a new instance of the class from the given file. + /// + /// The configuration for the decoder. + /// The file path to the image. + /// The configuration is null. + /// The path is null. + /// Image format not recognised. + /// Image contains invalid content. + /// A representing the asynchronous operation. + public static async Task LoadAsync(Configuration configuration, string path) + { + using (Stream stream = configuration.FileSystem.OpenRead(path)) + { + (Image img, _) = await LoadWithFormatAsync(configuration, stream).ConfigureAwait(false); + return img; + } + } + /// /// Create a new instance of the class from the given file. /// @@ -137,6 +168,29 @@ namespace SixLabors.ImageSharp } } + /// + /// Create a new instance of the class from the given file. + /// + /// The Configuration. + /// The file path to the image. + /// The decoder. + /// The configuration is null. + /// The path is null. + /// The decoder is null. + /// Image format not recognised. + /// Image contains invalid content. + /// A representing the asynchronous operation. + public static Task LoadAsync(Configuration configuration, string path, IImageDecoder decoder) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.NotNull(path, nameof(path)); + + using (Stream stream = configuration.FileSystem.OpenRead(path)) + { + return LoadAsync(configuration, stream, decoder); + } + } + /// /// Create a new instance of the class from the given file. ///