Example #1
0
        public static IImageResizeSettings ParseFromQueryString(IQueryCollection queryString)
        {
            var settings = new ImageResizeSettings();

            settings.Width           = IntParser.ParseOrDefault(GetQueryStringValue(queryString, QS_WIDTH));
            settings.Height          = IntParser.ParseOrDefault(GetQueryStringValue(queryString, QS_HEIGHT));
            settings.Anchor          = EnumParser.ParseOrDefault <ImageAnchorLocation>(GetQueryStringValue(queryString, QS_ANCHOR), settings.Anchor);
            settings.Mode            = EnumParser.ParseOrDefault <ImageFitMode>(GetQueryStringValue(queryString, QS_MODE), settings.Mode);
            settings.Scale           = EnumParser.ParseOrDefault <ImageScaleMode>(GetQueryStringValue(queryString, QS_SCALE), settings.Scale);
            settings.BackgroundColor = StringHelper.EmptyAsNull(GetQueryStringValue(queryString, QS_BACKGROUND_COLOR));

            return(settings);
        }
        public static IImageResizeSettings ParseFromQueryString(string queryString)
        {
            var qs       = HttpUtility.ParseQueryString(queryString);
            var settings = new ImageResizeSettings();

            settings.Width           = IntParser.ParseOrDefault(qs[QS_WIDTH]);
            settings.Height          = IntParser.ParseOrDefault(qs[QS_HEIGHT]);
            settings.Anchor          = EnumParser.ParseOrDefault <ImageAnchorLocation>(qs[QS_ANCHOR], settings.Anchor);
            settings.Mode            = EnumParser.ParseOrDefault <ImageFitMode>(qs[QS_MODE], settings.Mode);
            settings.Scale           = EnumParser.ParseOrDefault <ImageScaleMode>(qs[QS_SCALE], settings.Scale);
            settings.BackgroundColor = StringHelper.EmptyAsNull(qs[QS_BACKGROUND_COLOR]);

            return(settings);
        }
        private static ImageResizeSettings GetResizeSettings(IImageAssetRenderable asset, int?width, int?height)
        {
            var settings = new ImageResizeSettings();

            if (width.HasValue)
            {
                settings.Width = width.Value;
            }

            if (height.HasValue)
            {
                settings.Height = height.Value;
            }

            SetDefaultCrop(asset, settings);

            return(settings);
        }
Example #4
0
        /// <summary>
        /// Gets the url for an image asset, with optional resizing parameters
        /// </summary>
        /// <param name="asset">asset to get the url for</param>
        /// <param name="width">width to resize the image to</param>
        /// <param name="height">height to resize the image to</param>
        public string ImageAsset(IImageAssetRenderable asset, int?width, int?height = null)
        {
            if (asset == null)
            {
                return(string.Empty);
            }

            var settings = new ImageResizeSettings();

            if (width.HasValue)
            {
                settings.Width = width.Value;
            }

            if (height.HasValue)
            {
                settings.Height = height.Value;
            }

            SetDefaultCrop(asset, settings);

            return(ImageAsset(asset.ImageAssetId, asset.FileName, asset.Extension, settings));
        }