public static void then_should_return_true_given_new_objects()
            {
                // Arrange
                var imageLayer1 = new ImageLayer();
                var imageLayer2 = new ImageLayer();

                // Act
                var result = imageLayer1.Equals(imageLayer2);

                // Assert
                Assert.That(result, Is.True);
            }
            public static void then_should_return_false_given_null_second_layer()
            {
                // Arrange
                var imageLayer1 = new ImageLayer { Position = new Point(1, 1) };
                ImageLayer imageLayer2 = null;

                // Act
                var result = imageLayer1.Equals(imageLayer2);

                // Assert
                Assert.That(result, Is.False);
            }
            public static void then_should_return_false_given_different_layers()
            {
                // Arrange
                var imageLayer1 = new ImageLayer { Position = new Point(1, 1) };
                var imageLayer2 = new ImageLayer { Position = new Point(10, 10) };

                // Act
                var result = imageLayer1.Equals(imageLayer2);

                // Assert
                Assert.That(result, Is.False);
            }
            public static void then_should_return_true_given_image_and_size_and_opacity_and_position_same()
            {
                // Arrange
                var imageLayer1 = new ImageLayer
                {
                    Opacity = 50,
                    Position = new Point(1, 1),
                    Size = new Size(5, 5)
                };
                var imageLayer2 = new ImageLayer
                {
                    Opacity = 50,
                    Position = new Point(1, 1),
                    Size = new Size(5, 5)
                };

                // Act
                var result = imageLayer1.Equals(imageLayer2);

                // Assert
                Assert.That(result, Is.True);
            }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a image overlay to the current image.
        /// </summary>
        /// <param name="imageLayer">
        /// The <see cref="T:ImageProcessor.Imaging.ImageLayer"/> containing the properties necessary to add 
        /// the image overlay to the image.
        /// </param>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public ImageFactory Overlay(ImageLayer imageLayer)
        {
            if (this.ShouldProcess)
            {
                Overlay watermark = new Overlay { DynamicParameter = imageLayer };
                this.CurrentImageFormat.ApplyProcessor(watermark.ProcessImage, this);
            }

            return this;
        }
Exemplo n.º 6
0
        static byte[] Overlay(byte[] photo, Image overlay, int offset, int quality = 100, int opacity = 100)
        {
            var position = new Point();
            using (var ms = new MemoryStream(photo))
            {
                var image = Image.FromStream(ms);
                position.X = image.Width - overlay.Width - offset;
                position.Y = image.Height - overlay.Height - offset;
            }

            var imagelayer = new ImageLayer
            {
                Image = overlay,
                Position = position,
                Opacity = opacity
            };

            using (var inStream = new MemoryStream(photo))
            {
                using (var outStream = new MemoryStream())
                {
                    using (var imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        imageFactory.Load(inStream)
                            .Overlay(imagelayer)
                            .Format(new JpegFormat())
                            .Quality(quality)
                            .BackgroundColor(Color.White)
                            .Save(outStream);

                        return outStream.ToArray();
                    }
                }
            }
        }