예제 #1
0
        private void Distort(IMagickImage output, PointD[] corners, MagickGeometry inputDimensions, MagickGeometry trimmedDimensions, MagickColor backgroundColor)
        {
            MagickGeometry outputDimensions = GetDimensions(output, corners, inputDimensions, trimmedDimensions);

            double[] arguments = new double[16]
            {
                corners[0].X, corners[0].Y, 0, 0,
                corners[1].X, corners[1].Y, 0, outputDimensions.Height,
                corners[2].X, corners[2].Y, outputDimensions.Width, outputDimensions.Height,
                corners[3].X, corners[3].Y, outputDimensions.Width, 0
            };

            output.VirtualPixelMethod = VirtualPixelMethod.Background;
            output.BackgroundColor    = backgroundColor;
            if (!DisableViewportCrop)
            {
                output.SetArtifact("distort:viewport", GetViewport(arguments, corners).ToString());
            }
            var distortSettings = new DistortSettings()
            {
                Bestfit = true
            };

            output.Distort(DistortMethod.Perspective, distortSettings, arguments);
            output.BorderColor = backgroundColor;
            output.Border(2);
            output.ColorFuzz = ColorFuzz;
            output.Trim();
            output.RePage();
        }
예제 #2
0
            public void ShouldNotSetTheAttributesWhenTheyAreNotSpecified()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings();

                    settings.SetImageArtifacts(image);

                    Assert.Empty(image.ArtifactNames);
                }
            }
예제 #3
0
            public void ShouldNotSetTheAttributesWhenTheyAreNotSpecified()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings();

                    settings.SetImageArtifacts(image);

                    Assert.IsNull(image.GetArtifact("distort:scale"));
                    Assert.IsNull(image.GetArtifact("distort:viewport"));
                }
            }
예제 #4
0
            public void ShouldSetAnArtifactWhenTheViewportOfTheSettingsIsNotNull()
            {
                using (IMagickImage image = new MagickImage(Files.MagickNETIconPNG))
                {
                    DistortSettings settings = new DistortSettings()
                    {
                        Viewport = new MagickGeometry(1, 2, 300, 400),
                    };

                    image.Distort(DistortMethod.Barrel, settings, new double[] { 0, 0, 0, 0, 0 });

                    Assert.AreEqual("300x400+1+2", image.GetArtifact("distort:viewport"));
                }
            }
예제 #5
0
            public void ShouldSetAnArtifactWhenTheScaleOfTheSettingsIsNotNull()
            {
                using (IMagickImage image = new MagickImage(Files.MagickNETIconPNG))
                {
                    DistortSettings settings = new DistortSettings()
                    {
                        Scale = 5.2,
                    };

                    image.Distort(DistortMethod.Barrel, settings, new double[] { 0, 0, 0, 0, 0 });

                    Assert.AreEqual("5.2", image.GetArtifact("distort:scale"));
                }
            }
예제 #6
0
            public void ShouldSetViewport()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings()
                    {
                        Viewport = new MagickGeometry(1, 2, 3, 4),
                    };

                    settings.SetImageArtifacts(image);

                    Assert.AreEqual("3x4+1+2", image.GetArtifact("distort:viewport"));
                }
            }
예제 #7
0
            public void ShouldSetScale()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings()
                    {
                        Scale = 4.2,
                    };

                    settings.SetImageArtifacts(image);

                    Assert.AreEqual("4.2", image.GetArtifact("distort:scale"));
                }
            }
            public void ShouldRemoveViewport()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings
                    {
                        Viewport = new MagickGeometry(1, 2, 3, 4),
                    };

                    settings.SetImageArtifacts(image);
                    settings.RemoveImageArtifacts(image);

                    Assert.Empty(image.ArtifactNames);
                }
            }
            public void ShouldRemoveScale()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings
                    {
                        Scale = 4.2,
                    };

                    settings.SetImageArtifacts(image);
                    settings.RemoveImageArtifacts(image);

                    Assert.Empty(image.ArtifactNames);
                }
            }
예제 #10
0
                public void ShouldSetViewport()
                {
                    using (var image = new MagickImage())
                    {
                        var settings = new DistortSettings
                        {
                            Viewport = new MagickGeometry(1, 2, 3, 4),
                        };

                        ArtifactsHelper.SetImageArtifacts(image, settings);

                        Assert.Single(image.ArtifactNames);
                        Assert.Equal("3x4+1+2", image.GetArtifact("distort:viewport"));
                    }
                }
예제 #11
0
                public void ShouldSetScale()
                {
                    using (var image = new MagickImage())
                    {
                        var settings = new DistortSettings
                        {
                            Scale = 4.2,
                        };

                        ArtifactsHelper.SetImageArtifacts(image, settings);

                        Assert.Single(image.ArtifactNames);
                        Assert.Equal("4.2", image.GetArtifact("distort:scale"));
                    }
                }
            public void ShouldRemoveViewport()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings()
                    {
                        Viewport = new MagickGeometry(1, 2, 3, 4),
                    };

                    settings.SetImageArtifacts(image);
                    settings.RemoveImageArtifacts(image);

                    Assert.IsNull(image.GetArtifact("distort:viewport"));
                }
            }
            public void ShouldRemoveScale()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings()
                    {
                        Scale = 4.2,
                    };

                    settings.SetImageArtifacts(image);
                    settings.RemoveImageArtifacts(image);

                    Assert.IsNull(image.GetArtifact("distort:scale"));
                }
            }
예제 #14
0
        private IMagickImage DistortOverlay(IMagickImage grayShirt, IMagickImage overlay, PointD[] overlayCoordinates, PointD[] tshirtCoordinates)
        {
            using (var images = new MagickImageCollection())
            {
                grayShirt.Alpha(AlphaOption.Transparent);
                grayShirt.BackgroundColor = MagickColors.Transparent;
                images.Add(grayShirt);

                var croppedOverlay = CropOverlay(overlay, overlayCoordinates);
                croppedOverlay.VirtualPixelMethod = VirtualPixelMethod.Transparent;

                var arguments       = CreateArguments(overlayCoordinates, tshirtCoordinates);
                var distortSettings = new DistortSettings()
                {
                    Bestfit = true
                };
                croppedOverlay.Distort(DistortMethod.Perspective, distortSettings, arguments);
                ApplySharpen(croppedOverlay);

                images.Add(croppedOverlay);

                return(images.Merge());
            }
        }