Esempio n. 1
0
        public void ScaleTest2()
        {
            var source = new MediaSource("1045645", 200, 200);

            var rendition = new MediaRenditionInfo(
                host: "google.com",
                source: source,
                transformPath: "100x100/crop(0,0,85,20).png",
                width: 85,
                height: 20
                );

            var b = rendition.Scale(2f);

            Assert.Equal("1045645", b.SourcePath);
            Assert.Equal("crop(0,0,170,40)/170x40.png", b.TransformPath);

            var c = b.Scale(2f);

            Assert.Equal("1045645", c.SourcePath);
            Assert.Equal("crop(0,0,170,40)/340x80.png", c.TransformPath);

            var d = c.WithFormat("gif");

            Assert.Equal("1045645", d.SourcePath);
            Assert.Equal("crop(0,0,170,40)/340x80.gif", d.TransformPath);

            Assert.Equal(340, d.Width);
            Assert.Equal(80, d.Height);
        }
Esempio n. 2
0
        public void WithFormatTests()
        {
            var source = new MediaSource("1045645", 100, 100);

            var a = new MediaRenditionInfo("google.com", source, "100x100/crop(0,0,85,20).png", 85, 20);

            Assert.Equal("https://google.com/1045645;crop(0,0,85,20)/170x40.jpeg", a.Scale(2).WithFormat("jpeg").Url);
        }
Esempio n. 3
0
        public void ScaleTest()
        {
            var source = new MediaSource("1045645", 100, 100);

            var rendition = new MediaRenditionInfo("google.com", source, "100x100/crop(0,0,85,20).png", 85, 20);

            var b = rendition.Scale(2f);

            Assert.Equal("https://google.com/1045645;crop(0,0,85,20)/170x40.png", b.Url);
        }
Esempio n. 4
0
        public void Sign2()
        {
            var signer = new MD5Signer();

            var source = new MediaSource("1045645", 100, 100);

            var rendition = new MediaRenditionInfo("google.com", source, "100x100/crop(0,0,85,20).png", 85, 20, signer: signer);

            Assert.Equal("https://google.com/86a04659943b28fbef72f0bc42254aa0/1045645;100x100/crop(0,0,85,20).png", rendition.Url);
            Assert.Equal("https://google.com/f3a779d1806577fddfe7c211e7deb183/1045645;crop(0,0,85,20)/170x40.png", rendition.Scale(2f).Url);
            Assert.Equal("https://google.com/b9a9185d2e2b0ca878fe2f31df45ad6c/1045645;crop(0,0,85,20)/170x40.jpeg", rendition.Scale(2f).WithFormat("jpeg").Url);
        }
Esempio n. 5
0
        public void Sign1()
        {
            var signer = new Signer("sig");

            var source = new MediaSource("1045645", 1000, 1000);

            var rendition = new MediaRenditionInfo("google.com", source, "crop(0,0,850,200)/170x40.png", 85, 20, signer: signer);

            Assert.Equal("https://google.com/sig/1045645;crop(0,0,850,200)/170x40.png", rendition.Url);
            Assert.Equal("https://google.com/sig/1045645;crop(0,0,850,200)/340x80.png", rendition.Scale(2f).Url);
            Assert.Equal("https://google.com/sig/1045645;crop(0,0,850,200)/340x80.jpeg", rendition.Scale(2f).WithFormat("jpeg").Url);
        }
Esempio n. 6
0
        public void ScaleByFloatingPoint()
        {
            var source = new MediaSource("1045645", 100, 100);

            var rendition = new MediaRenditionInfo(host: null, source, "100x100/crop(0,0,85,20).png", 85, 20);

            var b = rendition.Scale(2.7f);

            Assert.Equal((int)(85 * 2.7), b.Width);
            Assert.Equal((int)(20 * 2.7), b.Height);

            Assert.Equal("crop(0,0,85,20)/229x54.png", b.TransformPath);
        }
        public void F()
        {
            var source = new MediaSource("37117398", 1125, 1500);

            var transformation = MediaTransformation.Parse("page(1)/crop(3,0,809,1056)/92x120/bg(fff).webp", source);

            Assert.Equal("page(1)/crop(3,0,809,1056)/92x120/bg(fff).webp", new MediaRenditionInfo(null, transformation, seperator: '/').TransformPath);

            var rendition = new MediaRenditionInfo(null, transformation, seperator: '/');

            var scaled = rendition.Scale(2);


            Assert.Equal("/37117398/page(1)/crop(3,0,809,1056)/184x240/bg(fff).webp", scaled.ToString());
        }
        public void DoubleResizeDown()
        {
            var transformation = MediaTransformation.Parse("blob;2000x2000/crop(97,21,480,360)/240x180.jpeg", _1_2000x2000);

            var pipeline = transformation.ToPipeline();

            // TODO: how do we flip crop & scale order...

            var scale = pipeline.Scale.Width / (double)pipeline.Crop.Value.Width; // 50%

            Assert.Equal("crop(97,21,480,360)/240x180.jpeg", pipeline.ToTransformPath());

            var rendition = new MediaRenditionInfo(null, transformation);

            Assert.Equal("crop(97,21,480,360)/240x180.jpeg", rendition.TransformPath);
        }
        public void D()
        {
            // https://carbonmade-media.accelerator.net/35240287;600x800/crop(80,0,450,800).webp

            var source = new MediaSource("35240287", 1125, 1500);

            var transformation = MediaTransformation.Parse("35240287;600x800/crop(80,0,450,800).webp", source);

            Assert.Equal("crop(150,0,843,1500)/450x800.webp", new MediaRenditionInfo(null, transformation).TransformPath);

            var rendition = new MediaRenditionInfo(null, transformation);

            rendition.Resize(100, 100);

            Assert.Equal("/35240287;crop(150,0,843,1500)/450x800.webp", rendition.ToString());
        }
Esempio n. 10
0
        public void FormatOnlyTest1()
        {
            var source = new MediaSource("1045645.png", 85, 20);

            var rendition = new MediaRenditionInfo("test.com", source, null, 85, 20);

            Assert.Null(rendition.TransformPath);
            Assert.Equal("1045645.png", rendition.Path);
            Assert.Equal("https://test.com/1045645.png", rendition.Url);

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

            var rendition2 = new MediaRenditionInfo("test.com", new MediaSource("1045645.png", 1, 1), null, 85, 20, signer: new Signer("hi"));

            Assert.Equal("https://test.com/hi/1045645.png", rendition2.Url);
        }
Esempio n. 11
0
        public void ClipTest1()
        {
            MediaRenditionInfo.Host = "google.com";

            var rendition = new MediaRenditionInfo(85, 20, "1045645/1:00/100x100.jpeg");

            var transform = rendition.TransformString[0];

            Assert.Equal("1:00/100x100.jpeg", rendition.TransformString);

            // 1045645/1:00/100x100.jpeg
            var transformation = MediaTransformation.ParsePath("1045645/00:01:00/100x100.jpeg");

            var clip = (Clip)transformation.GetTransforms()[0];

            Assert.Equal(TimeSpan.FromSeconds(60), clip.Start);
            Assert.Equal(TimeSpan.FromSeconds(60), clip.End);
        }
Esempio n. 12
0
        public void ScaleTest4()
        {
            var source = new MediaSource("1045645", 500, 500);

            var rendition = new MediaRenditionInfo(
                host:  null,
                source: source,
                transformPath: "100x100/crop(0,0,85,20).png",
                width: 85,
                height: 20
                );

            var b = rendition.Scale(2.7f);

            Assert.Equal(229, b.Width);
            Assert.Equal(54, b.Height);

            Assert.Equal("crop(0,0,425,100)/229x54.png", b.TransformPath);
            Assert.Equal("/1045645;crop(0,0,425,100)/229x54.png", b.Url);
        }
Esempio n. 13
0
        public void WithFormatTests()
        {
            MediaRenditionInfo.Host = "google.com";

            var rendition = new MediaRenditionInfo(85, 20, "1045645/100x100/crop:0-0_85x20.png");

            var b = rendition.Scale(2).Resample("abc").WithFormat("jpeg");

            Assert.Equal("https://google.com/1045645/200x200/crop:0-0_170x40/resample(abc).jpeg", b.Url);
        }
Esempio n. 14
0
        public void ScaleTest2()
        {
            MediaRenditionInfo.Host = "google.com";

            var rendition = new MediaRenditionInfo(85, 20, "1045645/100x100/crop:0-0_85x20.png");

            var b = rendition.Scale(2f);

            Assert.Equal("200x200/crop:0-0_170x40.png", b.TransformString);

            var c = b.Scale(2f);

            Assert.Equal("400x400/crop:0-0_340x80.png", c.TransformString);

            var d = c.WithFormat("gif");

            Assert.Equal("400x400/crop:0-0_340x80.gif", d.TransformString);
        }
Esempio n. 15
0
        public void ScaleTest()
        {
            MediaRenditionInfo.Host = "google.com";

            var rendition = new MediaRenditionInfo(85, 20, "1045645/100x100/crop:0-0_85x20.png");

            var b = rendition.Scale(2f);

            Assert.Equal("https://google.com/1045645/200x200/crop:0-0_170x40.png", b.Url);
        }
Esempio n. 16
0
        public void ResampleTest2()
        {
            MediaRenditionInfo.Host = "google.com";

            var rendition = new MediaRenditionInfo(85, 20, "1045645/100x100/crop:0-0_85x20.png");

            var b = rendition.Scale(2).Resample("abc");

            MediaRenditionInfo.Signer = new Signer("hey");

            Assert.Equal("https://google.com/hey/1045645/200x200/crop:0-0_170x40/resample(abc).png", b.Url);

            MediaRenditionInfo.Signer = null;
        }