Skip to content

Commit a79a447

Browse files
Merge branch 'master' into patch-1
2 parents 89774a3 + 9307048 commit a79a447

File tree

10 files changed

+1116
-21
lines changed

10 files changed

+1116
-21
lines changed

src/ImageSharp/Formats/Bmp/ImageExtensions.cs

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Copyright (c) Six Labors.
1+
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System.IO;
5-
5+
using System.Threading.Tasks;
66
using SixLabors.ImageSharp.Advanced;
77
using SixLabors.ImageSharp.Formats.Bmp;
88

@@ -13,13 +13,64 @@ namespace SixLabors.ImageSharp
1313
/// </summary>
1414
public static partial class ImageExtensions
1515
{
16+
/// <summary>
17+
/// Saves the image to the given stream with the bmp format.
18+
/// </summary>
19+
/// <param name="source">The image this method extends.</param>
20+
/// <param name="path">The file path to save the image to.</param>
21+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
22+
public static void SaveAsBmp(this Image source, string path) => SaveAsBmp(source, path, null);
23+
24+
/// <summary>
25+
/// Saves the image to the given stream with the bmp format.
26+
/// </summary>
27+
/// <param name="source">The image this method extends.</param>
28+
/// <param name="path">The file path to save the image to.</param>
29+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
30+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
31+
public static Task SaveAsBmpAsync(this Image source, string path) => SaveAsBmpAsync(source, path, null);
32+
33+
/// <summary>
34+
/// Saves the image to the given stream with the bmp format.
35+
/// </summary>
36+
/// <param name="source">The image this method extends.</param>
37+
/// <param name="path">The file path to save the image to.</param>
38+
/// <param name="encoder">The encoder to save the image with.</param>
39+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
40+
public static void SaveAsBmp(this Image source, string path, BmpEncoder encoder) =>
41+
source.Save(
42+
path,
43+
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance));
44+
45+
/// <summary>
46+
/// Saves the image to the given stream with the bmp format.
47+
/// </summary>
48+
/// <param name="source">The image this method extends.</param>
49+
/// <param name="path">The file path to save the image to.</param>
50+
/// <param name="encoder">The encoder to save the image with.</param>
51+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
52+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
53+
public static Task SaveAsBmpAsync(this Image source, string path, BmpEncoder encoder) =>
54+
source.SaveAsync(
55+
path,
56+
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance));
57+
58+
/// <summary>
59+
/// Saves the image to the given stream with the bmp format.
60+
/// </summary>
61+
/// <param name="source">The image this method extends.</param>
62+
/// <param name="stream">The stream to save the image to.</param>
63+
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
64+
public static void SaveAsBmp(this Image source, Stream stream) => SaveAsBmp(source, stream, null);
65+
1666
/// <summary>
1767
/// Saves the image to the given stream with the bmp format.
1868
/// </summary>
1969
/// <param name="source">The image this method extends.</param>
2070
/// <param name="stream">The stream to save the image to.</param>
2171
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
22-
public static void SaveAsBmp(this Image source, Stream stream) => source.SaveAsBmp(stream, null);
72+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
73+
public static Task SaveAsBmpAsync(this Image source, Stream stream) => SaveAsBmpAsync(source, stream, null);
2374

2475
/// <summary>
2576
/// Saves the image to the given stream with the bmp format.
@@ -32,5 +83,18 @@ public static void SaveAsBmp(this Image source, Stream stream, BmpEncoder encode
3283
source.Save(
3384
stream,
3485
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance));
86+
87+
/// <summary>
88+
/// Saves the image to the given stream with the bmp format.
89+
/// </summary>
90+
/// <param name="source">The image this method extends.</param>
91+
/// <param name="stream">The stream to save the image to.</param>
92+
/// <param name="encoder">The encoder to save the image with.</param>
93+
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
94+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
95+
public static Task SaveAsBmpAsync(this Image source, Stream stream, BmpEncoder encoder) =>
96+
source.SaveAsync(
97+
stream,
98+
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(BmpFormat.Instance));
3599
}
36-
}
100+
}
Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Copyright (c) Six Labors.
1+
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System.IO;
5-
5+
using System.Threading.Tasks;
66
using SixLabors.ImageSharp.Advanced;
77
using SixLabors.ImageSharp.Formats.Gif;
88

@@ -14,23 +14,87 @@ namespace SixLabors.ImageSharp
1414
public static partial class ImageExtensions
1515
{
1616
/// <summary>
17-
/// Saves the image to the given stream in the gif format.
17+
/// Saves the image to the given stream with the gif format.
18+
/// </summary>
19+
/// <param name="source">The image this method extends.</param>
20+
/// <param name="path">The file path to save the image to.</param>
21+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
22+
public static void SaveAsGif(this Image source, string path) => SaveAsGif(source, path, null);
23+
24+
/// <summary>
25+
/// Saves the image to the given stream with the gif format.
26+
/// </summary>
27+
/// <param name="source">The image this method extends.</param>
28+
/// <param name="path">The file path to save the image to.</param>
29+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
30+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
31+
public static Task SaveAsGifAsync(this Image source, string path) => SaveAsGifAsync(source, path, null);
32+
33+
/// <summary>
34+
/// Saves the image to the given stream with the gif format.
35+
/// </summary>
36+
/// <param name="source">The image this method extends.</param>
37+
/// <param name="path">The file path to save the image to.</param>
38+
/// <param name="encoder">The encoder to save the image with.</param>
39+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
40+
public static void SaveAsGif(this Image source, string path, GifEncoder encoder) =>
41+
source.Save(
42+
path,
43+
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance));
44+
45+
/// <summary>
46+
/// Saves the image to the given stream with the gif format.
47+
/// </summary>
48+
/// <param name="source">The image this method extends.</param>
49+
/// <param name="path">The file path to save the image to.</param>
50+
/// <param name="encoder">The encoder to save the image with.</param>
51+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
52+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
53+
public static Task SaveAsGifAsync(this Image source, string path, GifEncoder encoder) =>
54+
source.SaveAsync(
55+
path,
56+
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance));
57+
58+
/// <summary>
59+
/// Saves the image to the given stream with the gif format.
60+
/// </summary>
61+
/// <param name="source">The image this method extends.</param>
62+
/// <param name="stream">The stream to save the image to.</param>
63+
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
64+
public static void SaveAsGif(this Image source, Stream stream) => SaveAsGif(source, stream, null);
65+
66+
/// <summary>
67+
/// Saves the image to the given stream with the gif format.
1868
/// </summary>
1969
/// <param name="source">The image this method extends.</param>
2070
/// <param name="stream">The stream to save the image to.</param>
2171
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
22-
public static void SaveAsGif(this Image source, Stream stream) => source.SaveAsGif(stream, null);
72+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
73+
public static Task SaveAsGifAsync(this Image source, Stream stream) => SaveAsGifAsync(source, stream, null);
2374

2475
/// <summary>
25-
/// Saves the image to the given stream in the gif format.
76+
/// Saves the image to the given stream with the gif format.
2677
/// </summary>
2778
/// <param name="source">The image this method extends.</param>
2879
/// <param name="stream">The stream to save the image to.</param>
29-
/// <param name="encoder">The options for the encoder.</param>
80+
/// <param name="encoder">The encoder to save the image with.</param>
3081
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
3182
public static void SaveAsGif(this Image source, Stream stream, GifEncoder encoder) =>
3283
source.Save(
3384
stream,
3485
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance));
86+
87+
/// <summary>
88+
/// Saves the image to the given stream with the gif format.
89+
/// </summary>
90+
/// <param name="source">The image this method extends.</param>
91+
/// <param name="stream">The stream to save the image to.</param>
92+
/// <param name="encoder">The encoder to save the image with.</param>
93+
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
94+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
95+
public static Task SaveAsGifAsync(this Image source, Stream stream, GifEncoder encoder) =>
96+
source.SaveAsync(
97+
stream,
98+
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(GifFormat.Instance));
3599
}
36-
}
100+
}

src/ImageSharp/Formats/Jpeg/ImageExtensions.cs

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Copyright (c) Six Labors.
1+
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System.IO;
5-
5+
using System.Threading.Tasks;
66
using SixLabors.ImageSharp.Advanced;
77
using SixLabors.ImageSharp.Formats.Jpeg;
88

@@ -13,6 +13,48 @@ namespace SixLabors.ImageSharp
1313
/// </summary>
1414
public static partial class ImageExtensions
1515
{
16+
/// <summary>
17+
/// Saves the image to the given stream with the jpeg format.
18+
/// </summary>
19+
/// <param name="source">The image this method extends.</param>
20+
/// <param name="path">The file path to save the image to.</param>
21+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
22+
public static void SaveAsJpeg(this Image source, string path) => SaveAsJpeg(source, path, null);
23+
24+
/// <summary>
25+
/// Saves the image to the given stream with the jpeg format.
26+
/// </summary>
27+
/// <param name="source">The image this method extends.</param>
28+
/// <param name="path">The file path to save the image to.</param>
29+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
30+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
31+
public static Task SaveAsJpegAsync(this Image source, string path) => SaveAsJpegAsync(source, path, null);
32+
33+
/// <summary>
34+
/// Saves the image to the given stream with the jpeg format.
35+
/// </summary>
36+
/// <param name="source">The image this method extends.</param>
37+
/// <param name="path">The file path to save the image to.</param>
38+
/// <param name="encoder">The encoder to save the image with.</param>
39+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
40+
public static void SaveAsJpeg(this Image source, string path, JpegEncoder encoder) =>
41+
source.Save(
42+
path,
43+
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance));
44+
45+
/// <summary>
46+
/// Saves the image to the given stream with the jpeg format.
47+
/// </summary>
48+
/// <param name="source">The image this method extends.</param>
49+
/// <param name="path">The file path to save the image to.</param>
50+
/// <param name="encoder">The encoder to save the image with.</param>
51+
/// <exception cref="System.ArgumentNullException">Thrown if the path is null.</exception>
52+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
53+
public static Task SaveAsJpegAsync(this Image source, string path, JpegEncoder encoder) =>
54+
source.SaveAsync(
55+
path,
56+
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance));
57+
1658
/// <summary>
1759
/// Saves the image to the given stream with the jpeg format.
1860
/// </summary>
@@ -26,11 +68,33 @@ public static partial class ImageExtensions
2668
/// </summary>
2769
/// <param name="source">The image this method extends.</param>
2870
/// <param name="stream">The stream to save the image to.</param>
29-
/// <param name="encoder">The options for the encoder.</param>
71+
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
72+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
73+
public static Task SaveAsJpegAsync(this Image source, Stream stream) => SaveAsJpegAsync(source, stream, null);
74+
75+
/// <summary>
76+
/// Saves the image to the given stream with the jpeg format.
77+
/// </summary>
78+
/// <param name="source">The image this method extends.</param>
79+
/// <param name="stream">The stream to save the image to.</param>
80+
/// <param name="encoder">The encoder to save the image with.</param>
3081
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
3182
public static void SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder) =>
3283
source.Save(
3384
stream,
3485
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance));
86+
87+
/// <summary>
88+
/// Saves the image to the given stream with the jpeg format.
89+
/// </summary>
90+
/// <param name="source">The image this method extends.</param>
91+
/// <param name="stream">The stream to save the image to.</param>
92+
/// <param name="encoder">The encoder to save the image with.</param>
93+
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
94+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
95+
public static Task SaveAsJpegAsync(this Image source, Stream stream, JpegEncoder encoder) =>
96+
source.SaveAsync(
97+
stream,
98+
encoder ?? source.GetConfiguration().ImageFormatsManager.FindEncoder(JpegFormat.Instance));
3599
}
36-
}
100+
}

0 commit comments

Comments
 (0)