Example #1
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            var customRouteSection     = ConfigurationManager.GetSection("wingmanCustomRoutes") as WingmanRoutesConfigurationSection;
            var maxImageSizeConstraint = new MaximumImageSizeConstraint(customRouteSection.MaxImageDimension);
            var systemColorConstraint  = new SystemColorConstraint();

            foreach (WingmanCustomRouteElement route in customRouteSection.CustomRoutes)
            {
                var bgConstraint = route.UriRoot.Contains("{bgColor}") || !String.IsNullOrWhiteSpace(route.BackgroundColour)
                    ? (IRouteConstraint) new SystemColorConstraint()
                    : new RegexRouteConstraint("(.*)?");

                var originalExtensionConstraint = route.UriRoot.Contains("{originalExtension}") || !String.IsNullOrWhiteSpace(route.OriginalExtension)
                    ? (IRouteConstraint) new RegexRouteConstraint("jpg|png|gif|webp")
                    : new RegexRouteConstraint("(.*)?");

                var widthConstraint = !String.IsNullOrWhiteSpace(route.AllowedWidths)
                    ? (IRouteConstraint) new RegexRouteConstraint(route.AllowedWidths.Replace(",", "|"))
                    : maxImageSizeConstraint;

                var heightConstraint = !String.IsNullOrWhiteSpace(route.AllowedHeights)
                    ? (IRouteConstraint) new RegexRouteConstraint(route.AllowedHeights.Replace(",", "|"))
                    : maxImageSizeConstraint;

                routes.MapRoute(
                    name: route.Name,
                    url: $"{route.UriRoot}/{{*path}}",
                    defaults: new { controller = "ImageServe", action = route.Manipulation, quality = route.Quality, width = route.Width, originalExtension = route.OriginalExtension, bgColor = route.BackgroundColour, height = route.Height, rotationDegrees = route.RotationDegrees, pathPrefix = route.PathPrefix },
                    constraints: new { path = "(.*).(jpg|png|gif|webp)", originalExtension = originalExtensionConstraint, rotationDegrees = "0|90|180|270", width = widthConstraint, height = heightConstraint }
                    );
            }

            routes.MapRoute(
                name: "Plain",
                url: "{*path}",
                defaults: new { controller = "ImageServe", action = "Plain" }
                );
        }
Example #2
0
        public static void RegisterRoutes(int maxDimensionInt, RouteCollection routes)
        {
            var maxImageSizeConstraint = new MaximumImageSizeConstraint(maxDimensionInt);
            var systemColorConstraint  = new SystemColorConstraint();


            //Note: bg color should be a hexa value eg: FF2D00
            routes.MapRoute(
                name: "Fill Width, Quality, Height and BgColor",
                url: "derived/fill_h/{quality}/{width}/{height}/{bgColor}/{*path}",
                defaults: new { controller = "ImageServe", action = "Fill" },
                constraints: new { width = maxImageSizeConstraint, height = @"\d+", bgColor = systemColorConstraint, path = "(.*).(jpg|png|gif|webp)" }
                );

            routes.MapRoute(
                name: "Fill Width, Quality and Height",
                url: "derived/fill_h/{quality}/{width}/{height}/{*path}",
                defaults: new { controller = "ImageServe", action = "Fill" },
                constraints: new { width = maxImageSizeConstraint, height = @"\d+", path = "(.*).(jpg|png|gif|webp)" }
                );

            //Note: bg color should be a hexa value eg: FF2D00
            routes.MapRoute(
                name: "Fill Width, Quality and BgColor",
                url: "derived/fill/{quality}/{width}/{bgColor}/{*path}",
                defaults: new { controller = "ImageServe", action = "Fill" },
                constraints: new { width = maxImageSizeConstraint, bgColor = systemColorConstraint, path = "(.*).(jpg|png|gif|webp)" }
                );

            routes.MapRoute(
                name: "Fill Width, Quality",
                url: "derived/fill/{quality}/{width}/{*path}",
                defaults: new { controller = "ImageServe", action = "Fill" },
                constraints: new { width = maxImageSizeConstraint, path = "(.*).(jpg|png|gif|webp)" }
                );
        }
Example #3
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            var maxDimensionInt = 500;
            var maxDimension    = ConfigurationManager.AppSettings["MaximumImageDimension"];

            if (maxDimension == null)
            {
                throw new ConfigurationErrorsException("You must specify a key for MaximumImageDimension");
            }

            if (!Int32.TryParse(maxDimension, out maxDimensionInt))
            {
                throw new ConfigurationErrorsException("You must specify a valid integer for MaximumImageDimension");
            }

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            var maxImageSizeConstraint = new MaximumImageSizeConstraint(maxDimensionInt);

            var customRouteSection = ConfigurationManager.GetSection("wingmanCustomRoutes") as WingmanRoutesConfigurationSection;

            foreach (WingmanCustomRouteElement route in customRouteSection.CustomRoutes)
            {
                routes.MapRoute(
                    name: route.Name,
                    url: $"{route.UriRoot}/{{*path}}",
                    defaults: new { controller = "ImageServe", action = route.Manipulation, quality = route.Quality, width = route.Width, originalExtension = route.OriginalExtension },
                    constraints: new { path = "(.*).(jpg|png|gif|webp)", originalExtension = "jpg|png|gif|webp" }
                    );
            }

            if (!customRouteSection.DisableDefaultRouting)
            {
                routes.MapRoute(
                    name: "Crop Square With Format Change",
                    url: "derived/square/{quality}/{originalExtension}/{width}/{*path}",
                    defaults: new { controller = "ImageServe", action = "Square" },
                    constraints: new { width = maxImageSizeConstraint, path = "(.*).(jpg|png|gif|webp)", originalExtension = "jpg|png|gif|webp" }
                    );

                routes.MapRoute(
                    name: "Crop Square",
                    url: "derived/square/{quality}/{width}/{*path}",
                    defaults: new { controller = "ImageServe", action = "Square" },
                    constraints: new { width = maxImageSizeConstraint, path = "(.*).(jpg|png|gif|webp)" }
                    );

                routes.MapRoute(
                    name: "Resize Width With Format Change",
                    url: "derived/resize-w/{quality}/{originalExtension}/{width}/{*path}",
                    defaults: new { controller = "ImageServe", action = "ResizeToWidth" },
                    constraints: new { width = maxImageSizeConstraint, path = "(.*).(jpg|png|gif|webp)", originalExtension = "jpg|png|gif|webp" }
                    );

                routes.MapRoute(
                    name: "Resize Width",
                    url: "derived/resize-w/{quality}/{width}/{*path}",
                    defaults: new { controller = "ImageServe", action = "ResizeToWidth" },
                    constraints: new { width = maxImageSizeConstraint, path = "(.*).(jpg|png|gif|webp)" }
                    );
                RegisterFillManipulationRoutes.RegisterRoutes(maxDimensionInt, routes);
            }

            routes.MapRoute(
                name: "Plain",
                url: "{*path}",
                defaults: new { controller = "ImageServe", action = "Plain" }
                );
        }