Class that enables resizing of images
Inheritance: IDisposable
Exemple #1
0
        public void When_cropping_we_should_get_an_image_that_is_exactly_our_requested_size()
        {
            var original = GenerateTestImage(800, 600);

            var resized = new ResizeImage(original)
                .Crop()
                .ToSize(400, 300)
                .Save();

            resized.Width.Should().Be(400);
            resized.Height.Should().Be(300);
        }
Exemple #2
0
        public void It_pads_to_exactly_requested_size()
        {
            var original = GenerateTestImage(800, 600);

            var resizedImage = new ResizeImage(original)
                .Pad(Color.Black)
                .ToSize(331, 418)
                .Save();

            resizedImage.Width.Should().Be(331);
            resizedImage.Height.Should().Be(418);
        }
Exemple #3
0
        public void It_pads_with_the_correct_color()
        {
            var original = GenerateTestImage(800, 600, Color.Yellow);

            var resizedImage = new ResizeImage(original)
                .Pad(Color.Black)
                .ToSize(400, 600)
                .Save();

            resizedImage.GetPixel(0, 0).ToHex().Should().Be(Color.Black.ToHex());
            resizedImage.GetPixel(399, 599).ToHex().Should().Be(Color.Black.ToHex());
            resizedImage.GetPixel(0, 151).ToHex().Should().Be(Color.Yellow.ToHex());
            resizedImage.GetPixel(400, 449).ToHex().Should().Be(Color.Yellow.ToHex());
        }
Exemple #4
0
        public void It_calculates_constrain_correctly()
        {
            var original = GenerateTestImage(800, 600);

            var resizedImage = new ResizeImage(original)
                .Constrain()
                .ToSize(200, 200)
                .Save();

            resizedImage.Width.Should().Be(200);
            resizedImage.Height.Should().Be(150);

            resizedImage = new ResizeImage(original)
                .Constrain()
                .ToSize(465, 250)
                .Save();

            resizedImage.Width.Should().Be(333);
            resizedImage.Height.Should().Be(250);
        }