Skip to content

Commit

Permalink
Pass correct output size in ResizeMode.Min #892 (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
Obi-Dann authored and JimBobSquarePants committed Apr 23, 2019
1 parent 87c0a66 commit af0d3dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private static (Size, Rectangle) CalculateMinRectangle(
// Don't upscale
if (width > sourceWidth || height > sourceHeight)
{
return (new Size(sourceWidth, sourceWidth), new Rectangle(0, 0, sourceWidth, sourceHeight));
return (new Size(sourceWidth, sourceHeight), new Rectangle(0, 0, sourceWidth, sourceHeight));
}

// Find the shortest distance to go.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Transforms;
using SixLabors.Primitives;

using Xunit;

Expand Down Expand Up @@ -31,5 +33,24 @@ public void CalculateResizeWorkerHeightInWindowBands(
int actualCount = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(windowDiameter, width, sizeLimitHintInBytes);
Assert.Equal(expectedCount, actualCount);
}

[Fact]
public void CalculateMinRectangleWhenSourceIsSmallerThanTarget()
{
var sourceSize = new Size(200, 100);
var target = new Size(400, 200);

var actual = ResizeHelper.CalculateTargetLocationAndBounds(
sourceSize,
new ResizeOptions{
Mode = ResizeMode.Min,
Size = target
},
target.Width,
target.Height);

Assert.Equal(sourceSize, actual.Item1);
Assert.Equal(new Rectangle(0, 0, sourceSize.Width, sourceSize.Height), actual.Item2);
}
}
}

0 comments on commit af0d3dd

Please sign in to comment.