Exemple #1
0
        public MediaRenditionInfo Scale(double scale)
        {
            var a = MediaTransformation.Parse(Path);

            var b = new MediaTransformation(a.Source);

            foreach (var transform in a.GetTransforms())
            {
                switch (transform)
                {
                case ResizeTransform resize: b.Apply(resize * scale);      break;

                case CropTransform crop: b.Apply(crop.Scale(scale));   break;

                default: b.Apply(transform);           break;
                }
            }

            return(new MediaRenditionInfo(
                       host: host,
                       sourcePath: b.Source.Key,
                       transformPath: b.GetFullName(),
                       width: b.Width,
                       height: b.Height,
                       seperator: seperator,
                       signer: signer
                       ));
        }
Exemple #2
0
        public MediaRenditionInfo Crop(Rectangle rect)
        {
            var transformation = MediaTransformation.Parse(Path);

            transformation.Crop(rect);

            return(new MediaRenditionInfo(host, transformation, seperator, signer));
        }
Exemple #3
0
 public MediaRenditionInfo(
     string host,
     MediaTransformation transformation,
     char seperator    = ';',
     IUrlSigner signer = null)
     : this(
         host          : host,
         sourcePath    : transformation.Source.Key,
         transformPath : transformation.GetFullName(),
         width         : transformation.Width,
         height        : transformation.Height,
         seperator     : seperator
         )
 {
 }
Exemple #4
0
        public MediaRenditionInfo Scale(float scale)
        {
            var a = MediaTransformation.ParsePath(path);

            var b = new MediaTransformation(a.Source, a.Format);

            foreach (var transform in a.GetTransforms())
            {
                if (transform is Resize)
                {
                    var resize = (Resize)transform;

                    b.Transform(new Resize(resize.Size.Scale(scale)));
                }
                else if (transform is AnchoredResize)
                {
                    var resize = (AnchoredResize)transform;

                    b.Transform(new AnchoredResize(resize.Size.Scale(scale), resize.Anchor));
                }
                else if (transform is Crop)
                {
                    var crop = (Crop)transform;

                    b.Transform(new Crop(crop.Rectangle.Scale(scale)));
                }
                else
                {
                    b.Transform(transform);
                }
            }

            return new MediaRenditionInfo(b.Width, b.Height, b.GetPath());
        }
Exemple #5
0
 public MediaRenditionInfo(MediaTransformation transformation)
     : this(transformation, transformation.GetPath())
 { }
Exemple #6
0
        public static MediaTransformation ParsePath(string path)
        {
            // 100/transform/transform.format

            var lastDotIndex = path.LastIndexOf('.');
            var format = (lastDotIndex > 0) ? path.Substring(lastDotIndex + 1) : null;

            if (lastDotIndex > 0)
            {
                path = path.Substring(0, lastDotIndex);
            }

            var parts = path.TrimStart('/').Split('/');

            int i = 1;

            string id = "";
            var transforms = new List<ITransform>();

            foreach (var part in parts)
            {
                if (i == 1)
                {
                    id = part;
                }
                else
                {
                    ITransform transform;


                    if (char.IsDigit(part[0]))
                    {

                        if (part.Contains("-"))
                        {
                            transform = AnchoredResize.Parse(part);
                        }
                        else if (part.Contains(":"))
                        {
                            // 1:00

                            var time = TimeSpan.Parse(part);

                            transform = new Clip(time, time);
                        }
                        else
                        {
                            transform = Media.Resize.Parse(part);
                        }
                    }
                    else
                    {
                        var transformName = part.Split('(', ':')[0];

                        switch (transformName)
                        {
                            case "crop"   : transform = Media.Crop.Parse(part);        break;
                            case "rotate" : transform = Media.Rotate.Parse(part);      break;
                            case "flip"   : transform = Flip.Parse(part);              break;
                            default       : transform = Media.ApplyFilter.Parse(part); break;
                        }
                    }

                    transforms.Add(transform);
                }

                i++;
            }

            var rendition = new MediaTransformation(new MediaSource(id), format);

            foreach (var t in transforms)
            {
                rendition.Transform(t);
            }

            return rendition;
        }