diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs
index 1adb0b369..14d4c16cf 100644
--- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs
+++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs
@@ -466,19 +466,38 @@ namespace ImageProcessor.UnitTests
}
}
+ ///
+ /// Tests that the image's inside is rotated
+ ///
[Test]
public void ImageIsRotatedInside()
{
- int i = 0;
foreach (ImageFactory imageFactory in this.ListInputImages())
{
Image original = (Image)imageFactory.Image.Clone();
- imageFactory.RotateInside(45);
+ imageFactory.RotateInside(new RotateInsideLayer { Angle = 45, KeepImageDimensions = true });
imageFactory.Image.Width.Should().Be(original.Width, "because the rotated image dimensions should not have changed");
imageFactory.Image.Height.Should().Be(original.Height, "because the rotated image dimensions should not have changed");
+ }
+ }
+
+ ///
+ /// Tests that the image's inside is rotated and resized
+ ///
+ [Test]
+ public void ImageIsRotatedInsideAndResized()
+ {
+ int i = 0;
+ foreach (ImageFactory imageFactory in this.ListInputImages())
+ {
+ Image original = (Image)imageFactory.Image.Clone();
+ imageFactory.RotateInside(new RotateInsideLayer { Angle = 45, KeepImageDimensions = false });
+
+ imageFactory.Image.Width.Should().NotBe(original.Width, "because the rotated image dimensions should have changed");
+ imageFactory.Image.Height.Should().NotBe(original.Height, "because the rotated image dimensions should have changed");
- imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/rotateinside-" + i++.ToString() + ".jpg");
+ imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/rotateinsideresized-" + i++.ToString() + ".jpg");
}
}
diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs
index 7255d90f8..2355111b2 100644
--- a/src/ImageProcessor/ImageFactory.cs
+++ b/src/ImageProcessor/ImageFactory.cs
@@ -902,11 +902,11 @@ namespace ImageProcessor
///
/// The current instance of the class.
///
- public ImageFactory RotateInside(float degrees)
+ public ImageFactory RotateInside(RotateInsideLayer rotateLayer)
{
if (this.ShouldProcess)
{
- RotateInside rotate = new RotateInside { DynamicParameter = degrees };
+ RotateInside rotate = new RotateInside { DynamicParameter = rotateLayer };
this.CurrentImageFormat.ApplyProcessor(rotate.ProcessImage, this);
}
diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj
index 94848c1a8..919f7d8fe 100644
--- a/src/ImageProcessor/ImageProcessor.csproj
+++ b/src/ImageProcessor/ImageProcessor.csproj
@@ -214,6 +214,7 @@
+
diff --git a/src/ImageProcessor/Imaging/RotateInsideLayer.cs b/src/ImageProcessor/Imaging/RotateInsideLayer.cs
new file mode 100644
index 000000000..969c94a6e
--- /dev/null
+++ b/src/ImageProcessor/Imaging/RotateInsideLayer.cs
@@ -0,0 +1,30 @@
+// --------------------------------------------------------------------------------------------------------------------
+//
+// Copyright (c) James South.
+// Licensed under the Apache License, Version 2.0.
+//
+//
+// Encapsulates the properties required to add an rotation layer to an image.
+//
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace ImageProcessor.Imaging
+{
+ ///
+ /// A rotation layer to apply an inside rotation to an image
+ ///
+ public class RotateInsideLayer
+ {
+ ///
+ /// Gets or sets the rotation angle.
+ ///
+ public float Angle { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether to keep the image dimensions.
+ /// If set to true, the image is zoomed inside the area.
+ /// If set to false, the area is resized to match the rotated image.
+ ///
+ public bool KeepImageDimensions { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/ImageProcessor/Processors/RotateInside.cs b/src/ImageProcessor/Processors/RotateInside.cs
index cd740a981..6071b5ae5 100644
--- a/src/ImageProcessor/Processors/RotateInside.cs
+++ b/src/ImageProcessor/Processors/RotateInside.cs
@@ -4,7 +4,7 @@
// Licensed under the Apache License, Version 2.0.
//
//
-// Encapsulates methods to rotate an image.
+// Encapsulates methods to rotate the inside of an image.
//
// --------------------------------------------------------------------------------------------------------------------
@@ -15,6 +15,7 @@ namespace ImageProcessor.Processors
using System.Drawing;
using System.Drawing.Drawing2D;
using ImageProcessor.Common.Exceptions;
+ using ImageProcessor.Imaging;
///
/// Encapsulates the methods to rotate the inside of an image
@@ -49,14 +50,14 @@ namespace ImageProcessor.Processors
try
{
- float angle = this.DynamicParameter;
+ RotateInsideLayer rotateLayer = this.DynamicParameter;
// Center of the image
float rotateAtX = Math.Abs(image.Width / 2);
float rotateAtY = Math.Abs(image.Height / 2);
// Create a rotated image.
- newImage = this.RotateImage(image, rotateAtX, rotateAtY, angle);
+ newImage = this.RotateImage(image, rotateAtX, rotateAtY, rotateLayer);
image.Dispose();
image = newImage;
@@ -85,13 +86,13 @@ namespace ImageProcessor.Processors
///
/// Based on the Rotate effect
///
- private Bitmap RotateImage(Image image, float rotateAtX, float rotateAtY, float angle)
+ private Bitmap RotateImage(Image image, float rotateAtX, float rotateAtY, RotateInsideLayer rotateLayer)
{
// Create a new empty bitmap to hold rotated image
Bitmap newImage = new Bitmap(image.Width, image.Height);
newImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
- float zoom = Imaging.Rotation.ZoomAfterRotation(image.Width, image.Height, angle);
+ float zoom = Imaging.Rotation.ZoomAfterRotation(image.Width, image.Height, rotateLayer.Angle);
// Make a graphics object from the empty bitmap
using (Graphics graphics = Graphics.FromImage(newImage))
@@ -106,7 +107,7 @@ namespace ImageProcessor.Processors
graphics.TranslateTransform(rotateAtX, rotateAtY);
// Rotate the image
- graphics.RotateTransform(angle);
+ graphics.RotateTransform(rotateLayer.Angle);
// Zooms the image to fit the area
graphics.ScaleTransform(zoom, zoom);