public void Execute_transforms_each_frame()
        {
            var operation = new ResizeOperation("Test.gif", _directory, Settings());

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image =>
            {
                Assert.Equal(2, image.Frames.Count);
                AssertEx.All(image.Frames, frame => Assert.Equal(96, frame.PixelWidth));
            });
        }
Exemple #2
0
        public void VerifyNotRecommendedNameIsChanged()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(
                    s =>
            {
                s.FileName = @"nul";
            }));

            operation.Execute();

            Assert.IsTrue(File.Exists(_directory + @"\nul_.png"));
        }
Exemple #3
0
        public void VerifyFileNameIsSanitized()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(
                    s =>
            {
                s.FileName          = @"Directory\%1:*?""<>|(%2)";
                s.SelectedSize.Name = "Test\\/";
            }));

            operation.Execute();

            Assert.IsTrue(File.Exists(_directory + @"\Directory\Test_______(Test__).png"));
        }
        public void TransformHonorsFitWhenFit()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(x => x.SelectedSize.Fit = ResizeFit.Fit));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image =>
            {
                Assert.Equal(96, image.Frames[0].PixelWidth);
                Assert.Equal(48, image.Frames[0].PixelHeight);
            });
        }
        public void TransformHonorsUnit()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(
                    x =>
            {
                x.SelectedSize.Width  = 1;
                x.SelectedSize.Height = 1;
                x.SelectedSize.Unit   = ResizeUnit.Inch;
            }));

            operation.Execute();

            AssertEx.Image(_directory.File(), image => Assert.Equal(image.Frames[0].DpiX, image.Frames[0].PixelWidth, 0));
        }
Exemple #6
0
        public void TransformHonorsFitWhenStretch()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(x => x.SelectedSize.Fit = ResizeFit.Stretch));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image =>
            {
                Assert.AreEqual(Colors.Black, image.Frames[0].GetFirstPixel());
                Assert.AreEqual(96, image.Frames[0].PixelWidth);
                Assert.AreEqual(96, image.Frames[0].PixelHeight);
            });
        }
Exemple #7
0
        public void Transform_honors_fit_when_Fill()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(x => x.SelectedSize.Fit = ResizeFit.Fill));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image =>
            {
                Assert.Equal(Colors.White, image.Frames[0].GetFirstPixel());
                Assert.Equal(96, image.Frames[0].PixelWidth);
                Assert.Equal(96, image.Frames[0].PixelHeight);
            });
        }
        public void TransformHonorsShrinkOnlyWhenAutoWidth()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(
                    x =>
            {
                x.ShrinkOnly          = true;
                x.SelectedSize.Width  = 0;
                x.SelectedSize.Height = 288;
            }));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image => Assert.Equal(96, image.Frames[0].PixelHeight));
        }
        public void Transform_honors_shrink_only_when_auto_height()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(
                    x =>
            {
                x.ShrinkOnly          = true;
                x.SelectedSize.Width  = 288;
                x.SelectedSize.Height = 0;
            }));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image => Assert.Equal(192, image.Frames[0].PixelWidth));
        }
Exemple #10
0
        public void StripMetadataWhenNoMetadataPresent()
        {
            var operation = new ResizeOperation(
                "TestMetadataIssue1928_NoMetadata.jpg",
                _directory,
                Settings(
                    x =>
            {
                x.RemoveMetadata = true;
            }));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image => Assert.IsNull(((BitmapMetadata)image.Frames[0].Metadata).DateTaken));
            AssertEx.Image(
                _directory.File(),
                image => Assert.IsNull(((BitmapMetadata)image.Frames[0].Metadata).GetQuerySafe("System.Photo.Orientation")));
        }
        public void ExecuteKeepsDateModifiedWhenReplacingOriginals()
        {
            var path = Path.Combine(_directory, "Test.png");

            File.Copy("Test.png", path);

            var originalDateModified = File.GetLastWriteTimeUtc(path);

            var operation = new ResizeOperation(
                path,
                null,
                Settings(
                    s =>
            {
                s.KeepDateModified = true;
                s.Replace          = true;
            }));

            operation.Execute();

            Assert.Equal(originalDateModified, File.GetLastWriteTimeUtc(_directory.File()));
        }
        public void TransformIgnoresShrinkOnlyWhenPercent()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(
                    x =>
            {
                x.ShrinkOnly         = true;
                x.SelectedSize.Width = 133.3;
                x.SelectedSize.Unit  = ResizeUnit.Percent;
            }));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image =>
            {
                Assert.Equal(256, image.Frames[0].PixelWidth);
                Assert.Equal(128, image.Frames[0].PixelHeight);
            });
        }
        public void TransformIgnoresIgnoreOrientationWhenAuto()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(
                    x =>
            {
                x.IgnoreOrientation   = true;
                x.SelectedSize.Width  = 96;
                x.SelectedSize.Height = 0;
            }));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image =>
            {
                Assert.Equal(96, image.Frames[0].PixelWidth);
                Assert.Equal(48, image.Frames[0].PixelHeight);
            });
        }
Exemple #14
0
        public void TransformIgnoresOrientationWhenPortraitToLandscape()
        {
            var operation = new ResizeOperation(
                "TestPortrait.png",
                _directory,
                Settings(
                    x =>
            {
                x.IgnoreOrientation   = true;
                x.SelectedSize.Width  = 192;
                x.SelectedSize.Height = 96;
            }));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image =>
            {
                Assert.AreEqual(96, image.Frames[0].PixelWidth);
                Assert.AreEqual(192, image.Frames[0].PixelHeight);
            });
        }
Exemple #15
0
        public void Transform_ignores_orientation_when_landscape_to_portrait()
        {
            var operation = new ResizeOperation(
                "Test.png",
                _directory,
                Settings(
                    x =>
            {
                x.IgnoreOrientation   = true;
                x.SelectedSize.Width  = 96;
                x.SelectedSize.Height = 192;
            }));

            operation.Execute();

            AssertEx.Image(
                _directory.File(),
                image =>
            {
                Assert.Equal(192, image.Frames[0].PixelWidth);
                Assert.Equal(96, image.Frames[0].PixelHeight);
            });
        }