diff --git a/src/ImageProcessor.UnitTests/Imaging/RotationUnitTests.cs b/src/ImageProcessor.UnitTests/Imaging/RotationUnitTests.cs
index 32eb72e3ea..6e71079c62 100644
--- a/src/ImageProcessor.UnitTests/Imaging/RotationUnitTests.cs
+++ b/src/ImageProcessor.UnitTests/Imaging/RotationUnitTests.cs
@@ -18,5 +18,16 @@
result.Width.Should().Be(expectedWidth, "because the rotated width should have been calculated");
result.Height.Should().Be(expectedHeight, "because the rotated height should have been calculated");
}
+
+ [Test]
+ [TestCase(100, 100, 45, 1.41f)]
+ [TestCase(100, 100, 15, 1.22f)]
+ [TestCase(100, 200, 45, 2.12f)]
+ public void RotationZoomIsCalculated(int imageWidth, int imageHeight, float angle, float expected)
+ {
+ float result = Rotation.ZoomAfterRotation(imageWidth, imageHeight, angle);
+
+ result.Should().BeApproximately(expected, 0.01f, "because the zoom level after rotation should have been calculated");
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor/Imaging/Rotation.cs b/src/ImageProcessor/Imaging/Rotation.cs
index 8ae02f719d..b2ecd30cc8 100644
--- a/src/ImageProcessor/Imaging/Rotation.cs
+++ b/src/ImageProcessor/Imaging/Rotation.cs
@@ -39,5 +39,24 @@
return result;
}
+
+ ///
+ /// Calculates the zoom needed after the rotation.
+ ///
+ /// Width of the image.
+ /// Height of the image.
+ /// The angle.
+ /// The zoom needed
+ public static float ZoomAfterRotation(int imageWidth, int imageHeight, float angle)
+ {
+ double radians = angle * Math.PI / 180d;
+ double radiansSin = Math.Sin(radians);
+ double radiansCos = Math.Cos(radians);
+
+ double widthRotated = (imageWidth * radiansCos) + (imageHeight * radiansSin);
+ double heightRotated = (imageWidth * radiansSin) + (imageHeight * radiansCos);
+
+ return (float)(Math.Max(widthRotated, heightRotated) / 100);
+ }
}
}
\ No newline at end of file