Beispiel #1
0
        public EditableImage Apply(EditableImage image)
        {
            var bmp = image.Image;

            var borderWidth = (int)Math.Round(bmp.Width / 100 * BorderWidthPercentage);

            // For thicker borders try and keep to jpeg size blocks.
            if (borderWidth > 16)
            {
                borderWidth = (int)Math.Round(borderWidth / 8d) * 8;
            }

            int newWidth  = bmp.Width + borderWidth * 2;
            int newHeight = bmp.Height + borderWidth * 2;

            var newImage = new MagickImage(MagickColor.FromRgb(Colour.R, Colour.G, Colour.B), newWidth, newHeight);

            image.ApplyExistingSettingsToOtherImage(newImage);

            using (var clonedOriginal = image.Image.Clone())
            {
                newImage.Composite(clonedOriginal, Gravity.Center);

                image.Image = newImage;

                return(image);
            }
        }
        public EditableImage Apply(EditableImage image)
        {
            if (image == null)
            {
                return(null);
            }

            if (WatermarkImage == null || WatermarkLocation == null)
            {
                return(image);
            }

            var bmp = image.Image;

            var shortestSide = bmp.Height > bmp.Width ? bmp.Width : bmp.Height;
            var margin       = (int)Math.Round(shortestSide / 100 * WatermarkLocation.ImageMarginPercentage);
            var size         = (int)Math.Round(shortestSide / 100 * WatermarkLocation.ImageSizePercentage);

            var sizedWatermark = WatermarkImage.ScaleImage(size);
            var topLeft        = GetTopLeftPoint(image, sizedWatermark, WatermarkLocation.Location, margin);

            image.Image.Composite(sizedWatermark.Image, topLeft.X, topLeft.Y, CompositeOperator.Over);

            return(image);
        }