Esempio n. 1
0
        public static MvcHtmlString ImageSizer(string ImageUrl, string Title, int ThumbSize, bool ScaleImage, object imageAttributes = null)
        {
            ImageSizer img = new ImageSizer();

            img.ImageUrl        = ImageUrl;
            img.Title           = Title;
            img.ThumbSize       = ThumbSize;
            img.ScaleImage      = ScaleImage;
            img.imageAttributes = imageAttributes;

            return(new MvcHtmlString(img.ToHtmlString()));
        }
        public override string GetHtml()
        {
            if (this.ContentPage == null) {
                this.ContentPage = SiteData.GetCurrentPage();
            }

            this.ImgSrc = this.ContentPage.Thumbnail;
            this.Title = this.ContentPage.NavMenuText;

            if (String.IsNullOrEmpty(this.ImgSrc)) {
                // if page itself has no image, see if the image had been specified directly
                this.ImgSrc = this.ImageUrl;
            }

            if (!String.IsNullOrEmpty(this.ImgSrc)) {
                if (this.PerformURLResize) {
                    ImageSizer imgSzr = new ImageSizer();
                    imgSzr.ImageUrl = this.ImgSrc;
                    imgSzr.ThumbSize = this.ThumbSize;
                    imgSzr.ScaleImage = this.ScaleImage;

                    this.ImgSrc = imgSzr.ImageThumbUrl;
                }
            } else {
                this.ImgSrc = String.Empty;
            }

            if (!String.IsNullOrEmpty(this.ImgSrc)) {
                var imgBuilder = new TagBuilder("img");
                imgBuilder.MergeAttribute("src", this.ImgSrc);

                if (!String.IsNullOrEmpty(this.Title)) {
                    imgBuilder.MergeAttribute("alt", this.Title);
                    imgBuilder.MergeAttribute("title", this.Title);
                }

                var imgAttribs = (IDictionary<string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(imageAttributes);
                imgBuilder.MergeAttributes(imgAttribs);

                return imgBuilder.ToString(TagRenderMode.SelfClosing);
            } else {
                return String.Empty;
            }
        }