Skip to content

Commit e75bbb8

Browse files
committed
Pass correct output size in ResizeMode.Min #892
1 parent 87c0a66 commit e75bbb8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private static (Size, Rectangle) CalculateMinRectangle(
296296
// Don't upscale
297297
if (width > sourceWidth || height > sourceHeight)
298298
{
299-
return (new Size(sourceWidth, sourceWidth), new Rectangle(0, 0, sourceWidth, sourceHeight));
299+
return (new Size(sourceWidth, sourceHeight), new Rectangle(0, 0, sourceWidth, sourceHeight));
300300
}
301301

302302
// Find the shortest distance to go.

tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeHelperTests.cs

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

4+
using SixLabors.ImageSharp.Processing;
45
using SixLabors.ImageSharp.Processing.Processors.Transforms;
6+
using SixLabors.Primitives;
57

68
using Xunit;
79

@@ -31,5 +33,21 @@ public void CalculateResizeWorkerHeightInWindowBands(
3133
int actualCount = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(windowDiameter, width, sizeLimitHintInBytes);
3234
Assert.Equal(expectedCount, actualCount);
3335
}
36+
37+
[Fact]
38+
public void CalculateMinRectangle_WhenSourceIsSmallerThanTarget()
39+
{
40+
var sourceSize = new Size(200, 100);
41+
var target = new Size(400, 200);
42+
43+
var actual = ResizeHelper.CalculateTargetLocationAndBounds(
44+
sourceSize,
45+
new ResizeOptions(),
46+
target.Width,
47+
target.Height);
48+
49+
Assert.Equal(sourceSize, actual.Item1);
50+
Assert.Equal(new Rectangle(0, 0, sourceSize.Width, sourceSize.Height), actual.Item2);
51+
}
3452
}
3553
}

0 commit comments

Comments
 (0)