Exemple #1
0
        public void FilterTest1()
        {
            var t = MediaTransformation.Parse("33695921;100x100/" + string.Join('/',
                                                                                "blur(1)",
                                                                                "brightness(1)",
                                                                                "contrast(1)",
                                                                                "gamma(2)",
                                                                                "grayscale(1)",
                                                                                "invert(1)",
                                                                                "pixelate(1)",
                                                                                "sepia(1)",
                                                                                "sharpen(1)",
                                                                                "vibrance(1)"
                                                                                ) + ".jpeg");

            var pipe = Pipeline.From(jpeg_1920x2560, t.GetTransforms());


            Assert.True(pipe.Filters[0] is BlurFilter);
            Assert.True(pipe.Filters[1] is BrightnessFilter);
            Assert.True(pipe.Filters[2] is ContrastFilter);
            Assert.True(pipe.Filters[3] is GammaFilter);
            Assert.True(pipe.Filters[4] is GrayscaleFilter);
            Assert.True(pipe.Filters[5] is InvertFilter);
            Assert.True(pipe.Filters[6] is PixelateFilter);
            Assert.True(pipe.Filters[7] is SepiaFilter);
            Assert.True(pipe.Filters[8] is SharpenFilter);

            Assert.Equal("blob#1|>scale(100,100,lanczos3)|>blur(1)|>brightness(1)|>contrast(1)|>gamma(2)|>grayscale(1)|>invert(1)|>pixelate(1)|>sepia(1)|>sharpen(1)|>vibrance(1)|>JPEG::encode", pipe.Canonicalize());
        }
Exemple #2
0
        public void Filters()
        {
            var transformation = new MediaTransformation(jpeg_50x50)
                                 .Apply(new ContrastFilter(2f))
                                 .Apply(new GrayscaleFilter(1f))
                                 .Apply(new QuantizeFilter(256))
                                 .Apply(new SepiaFilter(1f))
                                 .Apply(new OpacityFilter(1f))
                                 .Apply(new SaturateFilter(1f))
                                 .Apply(new HueRotateFilter(90))
                                 .Encode(FormatId.Heif);

            Assert.Equal(100, transformation.Width);
            Assert.Equal(50, transformation.Height);

            Assert.Equal("contrast(2)/grayscale(1)/quantize(256)/sepia(1)/opacity(1)/saturate(1)/hueRotate(90deg).heif", transformation.GetTransformPath());

            var img = MediaTransformation.Parse(transformation.GetTransformPath());

            var transforms = img.GetTransforms();

            Assert.Equal(8, transforms.Count);

            Assert.Equal(2f, (transforms[0] as ContrastFilter).Amount);
            Assert.Equal(1f, (transforms[1] as GrayscaleFilter).Amount);
            Assert.Equal(256, (transforms[2] as QuantizeFilter).MaxColors);
            Assert.Equal(1f, (transforms[3] as SepiaFilter).Amount);
            Assert.Equal(1f, (transforms[4] as OpacityFilter).Amount);
            Assert.Equal(1f, (transforms[5] as SaturateFilter).Amount);
            Assert.Equal(90, (transforms[6] as HueRotateFilter).Degrees);

            Assert.Equal(FormatId.Heif, (transforms[7] as EncodeParameters).Format);
        }
Exemple #3
0
        public void StreamTests()
        {
            var t = MediaTransformation.Parse("33695921;drop(audio)/video(1mbs,profile:main).mp4");

            var pipe = Pipeline.From(t);

            Assert.Equal("drop(audio)/video(1mbs,profile:main).mp4", t.GetTransformPath());
        }
        public void Profile()
        {
            var transformation = MediaTransformation.Parse("profile(high444)/960x540.mp4", _37117398_960x540);

            Assert.Equal("high444", (transformation[0] as ProfileFilter).Name);

            Assert.Equal("960x540/profile(high444).mp4", new MediaRenditionInfo(null, transformation).TransformPath);
        }
        public void InvalidFormat()
        {
            var ex = Assert.Throws <InvalidTransformException>(() => {
                MediaTransformation.Parse("1;2000x2000/crop(97,21,480,360).jpeg&", _1_2000x2000);
            });

            Assert.Equal(2, ex.Index);
        }
Exemple #6
0
        public void Draw1()
        {
            var a = MediaTransformation.Parse("1;draw(circle(radius:5)).heif", jpeg_180x180);

            var pipe = Pipeline.From(a);

            Assert.Equal("blob#1|>scale(180,180,lanczos3)|>draw(circle(5))|>HEIF::encode", pipe.Canonicalize());
        }
Exemple #7
0
        public void DrawCircleWithUnitAndBlendMode()
        {
            var a = MediaTransformation.Parse("1;draw(circle(radius:50%),blendMode:color-burn).heif", jpeg_180x180);

            var pipe = Pipeline.From(a);

            Assert.Equal("blob#1|>scale(180,180,lanczos3)|>draw(circle(50%),blendMode:ColorBurn)|>HEIF::encode", pipe.Canonicalize());
        }
Exemple #8
0
        public void Draw2()
        {
            var a = MediaTransformation.Parse("1;draw(circle(radius:5),rectangle(100,100,red),fill:red,blendMode:burn).heif", jpeg_180x180);

            var pipe = Pipeline.From(a);

            Assert.Equal("blob#1|>scale(180,180,lanczos3)|>draw(circle(5),rectangle(100,100),fill:red,blendMode:ColorBurn)|>HEIF::encode", pipe.Canonicalize());
        }
Exemple #9
0
        public void Metadata3()
        {
            var a = MediaTransformation.Parse("1;metadata.json", jpeg_180x180);

            var pipe = Pipeline.From(a);

            Assert.Equal("blob#1|>metadata|>JSON::encode", pipe.Canonicalize());
        }
Exemple #10
0
        public void LeftAnchoredResizeAndRotatationTiff()
        {
            var rendition = new MediaTransformation(new MediaSource("1045645"))
                            .Apply(new ResizeTransform(new Size(50, 50), anchor: CropAnchor.Left))
                            .Rotate(180)
                            .Encode(FormatId.Tiff);

            Assert.Equal("50x50-l/rotate(180).tiff", rendition.GetTransformPath());
        }
Exemple #11
0
        public void LeftAnchoredResizeAndRotate90()
        {
            var transformation = new MediaTransformation(new MediaSource("1"))
                                 .Apply(new ResizeTransform(new Size(150, 50), anchor: CropAnchor.Left))
                                 .Rotate(90)
                                 .Encode(FormatId.Jpeg);

            Assert.Equal("150x50-l/rotate(90).jpeg", transformation.GetTransformPath());
        }
Exemple #12
0
        public void Scale1()
        {
            var rendition = new MediaTransformation(jpeg_85x20)
                            .Apply(new ScaleTransform(100, 200, InterpolaterMode.Cubic))
                            .Encode(FormatId.Jpeg);

            Assert.Equal(100, rendition.Width);
            Assert.Equal(200, rendition.Height);
        }
Exemple #13
0
        public void ResizePercent()
        {
            var rendition = new MediaTransformation(jpeg_85x20)
                            .Resize(Unit.Parse("300%"), Unit.Parse("200%"))
                            .Encode(FormatId.Jpeg);

            Assert.Equal(85 * 3, rendition.Width);
            Assert.Equal(20 * 2, rendition.Height);
        }
        public void Speed()
        {
            var transformation = MediaTransformation.Parse("speed(ultrafast)/960x540.mp4", _37117398_960x540);

            Assert.Equal("ultrafast", (transformation[0] as SpeedFilter).Name);
            Assert.Equal(FormatId.Mp4, transformation.Encoder.Format);

            Assert.Equal("960x540/speed(ultrafast).mp4", new MediaRenditionInfo(null, transformation).TransformPath);
        }
Exemple #15
0
        public void Pad1()
        {
            var rendition = new MediaTransformation(jpeg_85x20)
                            .Apply(new PadTransform(10))
                            .Encode(FormatId.Jpeg);

            Assert.Equal(105, rendition.Width);
            Assert.Equal(40, rendition.Height);
        }
        public void Tune()
        {
            var transformation = MediaTransformation.Parse("tune(animation)/960x540.webm", _37117398_960x540);

            Assert.Equal("animation", (transformation[0] as TuneFilter).Name);
            Assert.Equal(FormatId.WebM, transformation.Encoder.Format);

            Assert.Equal("960x540/tune(animation).webm", new MediaRenditionInfo(null, transformation).TransformPath);
        }
Exemple #17
0
        public void CoverTest1()
        {
            var a = MediaTransformation.Parse("1;1200x630,cover.jpeg", jpeg_180x180);

            var pipe = Pipeline.From(a);

            Assert.Equal("blob#1|>crop(0,43,180,94)|>scale(1200,630,lanczos3)|>JPEG::encode", pipe.Canonicalize());

            Assert.Equal(new Size(1200, 630), pipe.FinalSize);
        }
Exemple #18
0
        public void AnchoredResizeHasValidFileName()
        {
            var rendition = new MediaTransformation(new MediaSource("100"), "jpeg").Transform(new AnchoredResize(100, 100, Alignment.Center));
            Assert.Equal(@"100x100-c.jpeg", rendition.GetFullName());

            rendition = new MediaTransformation(new MediaSource("254565"), "jpeg")
                .Transform(new AnchoredResize(500, 100, Alignment.Center));

            Assert.Equal(@"500x100-c.jpeg", rendition.GetFullName());
        }
Exemple #19
0
        public void ResizeFit3()
        {
            var rendition = new MediaTransformation(jpeg_100x50)
                            .Apply(ResizeTransform.Parse("resize(25,50,fit)"))
                            .Encode(FormatId.Jpeg);

            var pipe = Pipeline.From(rendition);

            Assert.Equal("blob#1|>scale(25,12,lanczos3)|>JPEG::encode", pipe.Canonicalize());
        }
Exemple #20
0
        public void CenterAnchoredResizePng()
        {
            var rendition = new MediaTransformation(new MediaSource("1045645"), "png")
                .Transform(new AnchoredResize(100, 50, Alignment.Center));

            Assert.Equal(100, rendition.Width);
            Assert.Equal(50, rendition.Height);

            Assert.Equal("100x50-c.png", rendition.GetFullName());
        }
Exemple #21
0
        public void ResizePercent()
        {
            var rendition = new MediaTransformation(jpeg_85x20)
                            .Resize(Unit.Parse("300%"), Unit.Parse("200%"))
                            .Encode(FormatId.Jpeg);

            var pipe = Pipeline.From(rendition);

            Assert.Equal("blob#1|>scale(255,40,lanczos3)|>JPEG::encode", pipe.Canonicalize());
        }
        public void ParseTimeFilter2()
        {
            var transformation = MediaTransformation.Parse("time(2.6252524)/960x540.tiff", _37117398_960x540);

            var filter = transformation[0] as TimeFilter;

            Assert.Equal(2.6252524, filter.Value);

            Assert.Equal("time(2.6252524)/960x540.tiff", new MediaRenditionInfo(null, transformation).TransformPath);
        }
Exemple #23
0
        public void Scale1()
        {
            var rendition = new MediaTransformation(jpeg_85x20)
                            .Apply(new ScaleTransform(100, 200, InterpolaterMode.Cubic))
                            .Encode(FormatId.Jpeg);

            var pipe = Pipeline.From(rendition);

            Assert.Equal("blob#1|>scale(100,200,cubic)|>JPEG::encode", pipe.Canonicalize());
        }
        public void ParseTimeFilter1()
        {
            var transformation = MediaTransformation.Parse("00:00:01/960x540.heif", _37117398_960x540);

            var filter = transformation[0] as TimeFilter;

            Assert.Equal(1, filter.Value);

            Assert.Equal("time(1)/960x540.heif", new MediaRenditionInfo(null, transformation).TransformPath);
        }
Exemple #25
0
        public void Metadata1()
        {
            var a = MediaTransformation.Parse("1;metadata(width,height).json", jpeg_180x180);

            var pipe = Pipeline.From(a);

            Assert.Equal("width", pipe.Metadata.Properties[0]);
            Assert.Equal("height", pipe.Metadata.Properties[1]);

            Assert.Equal("blob#1|>metadata(width,height)|>JSON::encode", pipe.Canonicalize());
        }
Exemple #26
0
        public void CenterAnchoredResizePng()
        {
            var rendition = new MediaTransformation(new MediaSource("1"))
                            .Apply(new ResizeTransform(new Size(100, 50), CropAnchor.Center))
                            .Encode(FormatId.Png);

            Assert.Equal(100, rendition.Width);
            Assert.Equal(50, rendition.Height);

            Assert.Equal("100x50-c.png", rendition.GetTransformPath());
        }
Exemple #27
0
        public void RotatedSizeIsCorrect()
        {
            var source = new MediaSource("1", 100, 50);

            var transform = new MediaTransformation(source).Rotate(90).Encode(FormatId.Jpeg);

            Assert.Equal(50, transform.Width);
            Assert.Equal(100, transform.Height);

            Assert.Equal("rotate(90).jpeg", transform.GetTransformPath());
        }
        public void ToPipelineTests()
        {
            var transformation = MediaTransformation.Parse("1;2000x2000/crop(97,21,480,360).jpeg", _1_2000x2000);

            Assert.Equal(480, transformation.Width);
            Assert.Equal(360, transformation.Height);

            var pipeline = Pipeline.From(transformation);

            Assert.Equal("blob#1|>crop(97,21,480,360)|>JPEG::encode", pipeline.Canonicalize());
        }
Exemple #29
0
        public void CropAndScaleDisportionally()
        {
            var rendition = new MediaTransformation(jpeg_100x50)
                            .Resize(50, 100) // 50%, 200%
                            .Crop(0, 0, 25, 25)
                            .Encode(FormatId.Jpeg);

            var pipe = Pipeline.From(rendition);

            Assert.Equal("blob#1|>crop(0,0,50,12)|>scale(25,25,lanczos3)|>JPEG::encode", pipe.Canonicalize());
        }
        public void E()
        {
            var source = new MediaSource("35240287", 1125, 1500);

            var transformation = new MediaTransformation(source);

            transformation.Apply(MediaTransformation.ParseTransforms(new[] { "500x500" }));

            transformation.Encode(FormatId.Png);

            Assert.Equal("500x500.png", new MediaRenditionInfo(null, transformation).TransformPath);
        }
Exemple #31
0
        public void ExpiresTest()
        {
            var a = MediaTransformation.Parse("1;expires(1514686554).jpeg", jpeg_180x180);

            var filter = a.GetTransforms()[0] as ExpiresFilter;

            Assert.Equal("2017-12-31T02:15:54.0000000Z", filter.Timestamp.ToString("o"));

            var pipe = Pipeline.From(a);

            Assert.Equal("blob#1|>expires(1514686554)|>scale(180,180,lanczos3)|>JPEG::encode", pipe.Canonicalize());
        }
Exemple #32
0
        public void DrawPath1()
        {
            var a = MediaTransformation.Parse("1;draw(path(M150 0 L75 200 L225 200 Z)).heif", jpeg_180x180);

            var pipe = Pipeline.From(a);

            var draw = pipe.Filters[0] as DrawCommand;

            Assert.Equal("M150 0 L75 200 L225 200 Z", (draw.Objects[0] as PathShape).Content);

            Assert.Equal("blob#1|>scale(180,180,lanczos3)|>draw(path(M150 0 L75 200 L225 200 Z))|>HEIF::encode", pipe.Canonicalize());
        }
Exemple #33
0
        public void BuilderTests()
        {
            var transformation = new MediaTransformation(new MediaSource("1045645", 50, 50), "jpeg")
                .Resize(100, 100)
                .Rotate(90)
                .ApplyFilter("sepia", 1);

            Assert.Equal("1045645", transformation.Source.Key);
            Assert.Equal(100, transformation.Width);
            Assert.Equal(100, transformation.Height);

            Assert.Equal("100x100/rotate(90)/sepia(1).jpeg", transformation.GetFullName());
        }
Exemple #34
0
        public void CropPng()
        {
            var rendition = new MediaTransformation(new MediaSource("1045645"), "png")
                .Resize(100, 100)
                .Crop(0, 0, 85, 20);

            Assert.Equal("100x100/crop:0-0_85x20.png", rendition.GetFullName());
            Assert.Equal("1045645/100x100/crop:0-0_85x20.png", rendition.GetPath());

            var rendition2 = MediaTransformation.ParsePath(rendition.GetPath());

            Assert.Equal("1045645", rendition2.Source.Key);
            Assert.Equal("png", rendition2.Format);
            Assert.Equal(2, rendition2.GetTransforms().Count);
            Assert.Equal("100x100", rendition2.GetTransforms()[0].ToString());
            Assert.Equal("crop:0-0_85x20", rendition2.GetTransforms()[1].ToString());
        }
Exemple #35
0
        public void LeftAnchoredResizeAndRotatationTiff()
        {
            var rendition = new MediaTransformation(new MediaSource("1045645"), "tiff")
                .Transform(new AnchoredResize(50, 50, Alignment.Left))
                .Rotate(180);

            Assert.Equal("50x50-l/rotate(180).tiff", rendition.GetFullName());
        }
Exemple #36
0
        public void ResizeAndRotated90()
        {
            var rendition = new MediaTransformation(new MediaSource("1045645"), "jpeg")
                .Resize(50, 50)
                .Crop(0, 0, 85, 20)
                .Rotate(90);

            Assert.Equal("50x50/crop:0-0_85x20/rotate(90).jpeg", rendition.GetFullName());

            var rendition2 = MediaTransformation.ParsePath(rendition.GetPath());

            Assert.Equal(20, rendition.Width);
            Assert.Equal(85, rendition.Height);

            Assert.Equal(3, rendition2.GetTransforms().Count);

            Assert.Equal(90, ((Rotate)rendition2.GetTransforms()[2]).Angle);
        }
Exemple #37
0
        public void ResizeJpeg()
        {
            var rendition = new MediaTransformation(new MediaSource("64a5e3944d4f11c05cde1a60efa9b86e9c4c6e54f3cb17269454472fdfa88d89"), "jpeg").Resize(85, 20);

            Assert.Equal("85x20.jpeg", rendition.GetFullName());
            Assert.Equal("64a5e3944d4f11c05cde1a60efa9b86e9c4c6e54f3cb17269454472fdfa88d89/85x20.jpeg", rendition.GetPath());

            var rendition2 = MediaTransformation.ParsePath(rendition.GetPath());

            Assert.Equal("jpeg", rendition2.Format);
            Assert.Equal(1, rendition2.GetTransforms().Count);
            Assert.Equal("85x20", rendition2.GetTransforms()[0].ToString());
        }
Exemple #38
0
        public void RotatedSizeIsCorrect()
        {
            var rendition = new MediaTransformation(new MediaSource("1", 100, 50), "jpeg").Rotate(90);

            Assert.Equal(50, rendition.Width);
            Assert.Equal(100, rendition.Height);

            Assert.Equal("1/rotate(90).jpeg", rendition.GetPath());
        }
Exemple #39
0
        public void Filters()
        {
            var transformation = new MediaTransformation(new MediaSource("1045645", 100, 50), "jpeg")
                .Transform(new ApplyFilter("contrast", "2"))
                .Transform(new ApplyFilter("grayscale", "1"))
                .Transform(new ApplyFilter("sepia", "1"));

            Assert.Equal(100, transformation.Width);
            Assert.Equal(50, transformation.Height);

            Assert.Equal("contrast(2)/grayscale(1)/sepia(1).jpeg", transformation.GetFullName());

            var rendition2 = MediaTransformation.ParsePath(transformation.GetPath());
            Assert.Equal(3, rendition2.GetTransforms().Count);

            Assert.Equal("contrast", ((ApplyFilter)rendition2.GetTransforms()[0]).Name);
            Assert.Equal("grayscale", ((ApplyFilter)rendition2.GetTransforms()[1]).Name);
            Assert.Equal("sepia", ((ApplyFilter)rendition2.GetTransforms()[2]).Name);
        }
Exemple #40
0
        public void OrientedPhotoHasCorrectThings()
        {
            var rendition = new MediaTransformation(new MediaSource("1", 100, 50), MediaOrientation.Rotate90, "jpeg");

            Assert.Equal(50, rendition.Width);
            Assert.Equal(100, rendition.Height);

            Assert.Equal("rotate(90)", rendition.GetTransforms()[0].ToString());

            Assert.Equal("1/rotate(90).jpeg", rendition.GetPath());
        }
Exemple #41
0
        public void ResizedJpegUriIsCorrect()
        {
            var rendition = new MediaTransformation(new MediaSource("64a5e3944d4f11c05cde1a60efa9b86e9c4c6e54f3cb17269454472fdfa88d89"), "jpeg").Resize(85, 20);

            Assert.Equal("64a5e3944d4f11c05cde1a60efa9b86e9c4c6e54f3cb17269454472fdfa88d89/85x20.jpeg", rendition.GetPath());
        }
Exemple #42
0
        public void LeftAnchoredResizeAndRotate90()
        {
            var transformation = new MediaTransformation(new MediaSource("1045645"), "jpeg")
                .Transform(new AnchoredResize(150, 50, Alignment.Left))
                .Rotate(90);

            Assert.Equal("150x50-l/rotate(90).jpeg", transformation.GetFullName());
        }