Added rotation support for image watermark

This commit is contained in:
DESKTOP\Administrator
2026-06-14 21:10:47 +03:00
parent 98438b8c0a
commit a15e9a9ddd
2 changed files with 15 additions and 6 deletions
+5 -5
View File
@@ -25,7 +25,7 @@ namespace UnitTest
Font = availableFont.CreateFont(1),
Text = "Test",
Style = { Color = Color.White },
Layout = { Position = ImagePosition.BottomCenter , RotateAngle = 90 }
Layout = { Position = ImagePosition.BottomCenter, RotateAngle = 45 }
};
var resultedImage = watermarker.ProcessImage("TestImages/2.png", "test/text", watermark);
@@ -105,7 +105,7 @@ namespace UnitTest
Font = availableFont.CreateFont(1),
Text = "Test",
Style = { Color = Color.White },
Layout = { Position = ImagePosition.BottomCenter , RotateAngle = 90 }
Layout = { Position = ImagePosition.BottomCenter, RotateAngle = 45 }
};
var resultedImage = pipeline.ProcessImage("TestImages/2.png", "test/pipeline/text", watermark);
@@ -123,7 +123,7 @@ namespace UnitTest
var watermark = new ImageWatermark {
ImagePath = "TestImages/sample_wm.png",
Layout = { Position = ImagePosition.Center, Scale = 1 },
Layout = { Position = ImagePosition.Center, Scale = 1, RotateAngle = 45 },
Style = { Opacity = 1 }
};
@@ -150,7 +150,7 @@ namespace UnitTest
Text = "Test",
Font = availableFont.CreateFont(1),
Style = { Color = Rgba32.ParseHex("FFFFFF50"), Pave = true },
Layout = { Scale = 1f, Position = ImagePosition.TopLeft }
Layout = { Scale = 1f, Position = ImagePosition.TopLeft, RotateAngle = 45 }
};
var results = pipeline.ProcessDirectory("TestImages", "test/pipeline/text/dir", watermark);
@@ -167,7 +167,7 @@ namespace UnitTest
var watermark = new ImageWatermark {
ImagePath = "TestImages/sample_wm.png",
Layout = { Position = ImagePosition.Center, Scale = 1},
Layout = { Position = ImagePosition.Center, Scale = 1, RotateAngle = 45},
Style = { Pave = true, Opacity = 1}
};
@@ -236,7 +236,16 @@ namespace Watermark.Net.src.WatermarkNet.Core
if (watermark.Style.Color != null)
processingContext.BackgroundColor((Color)watermark.Style.Color);
watermarkImage.Mutate(x => x.Resize(new Size((int)scaledWmWidth, (int)scaledWmHeight)));
watermarkImage = watermarkImage.Clone(x =>
{
x.Resize((int)scaledWmWidth, (int)scaledWmHeight);
if (watermark.Layout.RotateAngle != 0)
{
x.Rotate(watermark.Layout.RotateAngle);
}
});
var wmPositionOrigin = CalcWatermarkOrigin(targetImage.Width, targetImage.Height, watermarkImage.Width, watermarkImage.Height, watermark.Layout.Position);
if (watermark.Style.Pave)