예제 #1
0
        public static WatermarkSettings FromConfig(WatermarkConfiguration config)
        {
            var settings = new WatermarkSettings
            {
                Position = config.Position ?? WatermarkPosition.BottomRight,
                Text     = config.Text
            };

            if (config.Colors is null || config.Colors.Count() == 0)
            {
                settings.Colors = new[] { SKColors.Red, SKColors.Purple };
            }
예제 #2
0
 public static ImageBase Create(WatermarkConfiguration configuration, PointF originalScale)
 => configuration switch
 {
     null => new EmptyWatermark(),
 public WatermmarkGenerator(WatermarkConfiguration ParamConfig)
 {
     this.config = ParamConfig;
 }
예제 #4
0
        public static IImageProcessingContext ApplyWatermark(this IImageProcessingContext processingContext, WatermarkConfiguration config)
        {
            if (config is null)
            {
                return(processingContext);
            }
            else if (!string.IsNullOrEmpty(config.SourceFile))
            {
                return(processingContext.ApplyWatermark(config.SourceFile, config.Opacity));
            }

            var settings = WatermarkSettings.FromConfig(config);
            var size     = processingContext.GetCurrentSize();

            // Create a new image for the watermark layer.
            using var watermark = new Image <Rgba32>(size.Width, size.Height);

            var xOffeset = 0;
            var yOffeset = 0;

            watermark.Mutate(ctx =>
            {
                // Draw the watermark.
                ctx.DrawWatermark(settings);

                var angle = 0.0f;
                if ((settings.Position == WatermarkPosition.BottomLeft) || (settings.Position == WatermarkPosition.TopRight))
                {
                    angle = 45.0f;
                    // Calculate the x/y offsets for later when we draw the watermark on top of the source image.
                    xOffeset = -(int)((Math.Sin(angle) * (size.Width / 2)) / 2);
                    yOffeset = -(int)((Math.Sin(angle) * (size.Height / 2)) / 2);
                }
                else if ((settings.Position == WatermarkPosition.BottomRight) || (settings.Position == WatermarkPosition.TopLeft))
                {
                    angle = -45.0f;
                    // Calculate the x/y offsets for later when we draw the watermark on top of the source image.
                    xOffeset = (int)((Math.Sin(angle) * (size.Width / 2)) / 2);
                    yOffeset = (int)((Math.Sin(angle) * (size.Height / 2)) / 2);
                }
                if (angle != 0)
                {
                    ctx.Rotate(angle);
                }
            });

            // Draw the watermark layer on top of the source image.
            processingContext.DrawImage(watermark, new Point(xOffeset, yOffeset), 1);

            return(processingContext);
        }
예제 #5
0
 public WatermarkTextBanner(WatermarkConfiguration configuration, PointF originalScale) : base(string.Empty)
 {
     this.configuration = configuration;
     this.originalScale = originalScale;
 }