Skip to content

Commit 00e0508

Browse files
authored
Merge pull request #1003 from SixLabors/issue/999
Fix #999 and add tests
2 parents fafba05 + 73f3c7a commit 00e0508

File tree

10 files changed

+337
-263
lines changed

10 files changed

+337
-263
lines changed

src/ImageSharp/Processing/Extensions/ResizeExtensions.cs

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

44
using SixLabors.ImageSharp.Processing.Processors.Transforms;
@@ -12,16 +12,6 @@ namespace SixLabors.ImageSharp.Processing
1212
/// </summary>
1313
public static class ResizeExtensions
1414
{
15-
/// <summary>
16-
/// Resizes an image in accordance with the given <see cref="ResizeOptions"/>.
17-
/// </summary>
18-
/// <param name="source">The image to resize.</param>
19-
/// <param name="options">The resize options.</param>
20-
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
21-
/// <remarks>Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image or the nearest possible ratio.</remarks>
22-
public static IImageProcessingContext Resize(this IImageProcessingContext source, ResizeOptions options)
23-
=> source.ApplyProcessor(new ResizeProcessor(options, source.GetCurrentSize()));
24-
2515
/// <summary>
2616
/// Resizes an image to the given <see cref="Size"/>.
2717
/// </summary>
@@ -128,7 +118,18 @@ public static IImageProcessingContext Resize(
128118
Rectangle sourceRectangle,
129119
Rectangle targetRectangle,
130120
bool compand)
131-
=> source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand), sourceRectangle);
121+
{
122+
var options = new ResizeOptions
123+
{
124+
Size = new Size(width, height),
125+
Mode = ResizeMode.Manual,
126+
Sampler = sampler,
127+
TargetRectangle = targetRectangle,
128+
Compand = compand
129+
};
130+
131+
return source.ApplyProcessor(new ResizeProcessor(options, source.GetCurrentSize()), sourceRectangle);
132+
}
132133

133134
/// <summary>
134135
/// Resizes an image to the given width and height with the given sampler and source rectangle.
@@ -150,6 +151,27 @@ public static IImageProcessingContext Resize(
150151
IResampler sampler,
151152
Rectangle targetRectangle,
152153
bool compand)
153-
=> source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand));
154+
{
155+
var options = new ResizeOptions
156+
{
157+
Size = new Size(width, height),
158+
Mode = ResizeMode.Manual,
159+
Sampler = sampler,
160+
TargetRectangle = targetRectangle,
161+
Compand = compand
162+
};
163+
164+
return Resize(source, options);
165+
}
166+
167+
/// <summary>
168+
/// Resizes an image in accordance with the given <see cref="ResizeOptions"/>.
169+
/// </summary>
170+
/// <param name="source">The image to resize.</param>
171+
/// <param name="options">The resize options.</param>
172+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
173+
/// <remarks>Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image or the nearest possible ratio.</remarks>
174+
public static IImageProcessingContext Resize(this IImageProcessingContext source, ResizeOptions options)
175+
=> source.ApplyProcessor(new ResizeProcessor(options, source.GetCurrentSize()));
154176
}
155-
}
177+
}

0 commit comments

Comments
 (0)