+1-888-365-2779
Try Now
More in this section

Forums / Designing with Sitefinity / Change Default Thumbnail Size on ImageGallery

Change Default Thumbnail Size on ImageGallery

2 posts, 0 answered
  1. Jeremy
    Jeremy avatar
    17 posts
    Registered:
    28 Jul 2010
    13 Aug 2010
    Link to this post
    I would like to make the default thumbnail larger in the ImageGallery. How can I do this?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    13 Aug 2010
    Link to this post
    Hi Jeremy,

    Libraries provider has two properties that you can use - they have to be declared in the Libraries provider registration

    DefaultThumbnailWidth - Gets the default width of the thumbnail, used when the thumbnails are automatically generated

    DefaultThumbnailHeight - Gets the default height of the thumbnail, used when the thumbnails are automatically generated

    This will set default values for the generated thumbs. After that you have to style the public control - ImageGallery .


    The ImageGallery control uses attributes (QueryStrings) of the built -in handler to scale the images

    • width, height -> the strings provide measures and the image is stretched to fit in them. Example:

      http://www.my_domain.com/MyFile.sflb?width=100&height=100

    • decreaseOnly -> when true, the image could only be decreased to fit in the measures set by the width and height strings. Still, if the image is smaller, it would not be enlarged. Example:

      http://www.my_domain.com/MyFile.sflb?decreaseOnly=true&width=100&height=100

    • proportional -> when true (by default), the image is stretched only proportionally until it fits in the measures set by the width and height strings.  Example: 

      http://www.my_domain.com/MyFile.sflb?proportional=true&width=100&height=100 


    If you want to remove these parameters you have to override the control  as shown below

    public class ImageGalleryCustom : ImageGallery
    {
        public ImageGalleryCustom()
        {
        }
     
        // YOU NEED TO OVERRY TEMPLATE PROPERTIES TO SET YOUR TEMPLATE
     
        protected override void SetListMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetListMetadata(itemContainer, contentItem);
     
            switch(galleryViewMode)
            {
                case GalleryViewMode.Lightbox:
                case GalleryViewMode.BigImageAndList:
                case GalleryViewMode.ListDetails:
                    HyperLink downloadLink = itemContainer.FindControl("DownloadLink") as HyperLink;
     
                    if (downloadLink != null)
                    {
                        if (this.galleryViewMode != GalleryViewMode.Lightbox)
                            this.AddPersistenceToLink(downloadLink);
     
                        string url = contentItem.Url +
                            this.Manager.Provider.ThumbnailExtension;
                        if (this.ThumbnailMaxSize > 0)
                        {
                            url += "?width=" + this.ThumbnailMaxSize.ToString() +
                               "&height=" + this.ThumbnailMaxSize.ToString() +
                               "&proportional=false";
                        }
                        downloadLink.ImageUrl = ResolveUrl(url);
                        downloadLink.Text = contentItem.GetMetaData("AlternateText") as string;
                        if (this.galleryViewMode == GalleryViewMode.ListDetails)
                        {
                            downloadLink.NavigateUrl = GetItemUrl(contentItem, this.SingleItemUrl);
     
                            HyperLink titleLink = itemContainer.FindControl("Title") as HyperLink;
                            if (titleLink != null)
                            {
                                titleLink.NavigateUrl = downloadLink.NavigateUrl;
                                titleLink.Text = contentItem.GetMetaData("Name") as string;
                                this.AddPersistenceToLink(titleLink);
                            }
                        }
                        else if (this.galleryViewMode == GalleryViewMode.Lightbox || this.galleryViewMode == GalleryViewMode.BigImageAndList)
                        {
                            downloadLink.NavigateUrl = base.GetItemUrl(contentItem, null);
                            HyperLink titleLink = itemContainer.FindControl("Title") as HyperLink;
                            if (titleLink != null)
                            {
                                titleLink.NavigateUrl = downloadLink.NavigateUrl;
                                titleLink.Text = contentItem.GetMetaData("Name") as string;
                            }
                            downloadLink.ToolTip = contentItem.GetMetaData("Name") as string;
                        }
                    }
     
                    break;
            }
     
          
        }
     
        void AddPersistenceToLink(HyperLink ctrl)
        {
     
            if (ContentItemKeyPersistance == ItemKeyPersistanceMode.Cookie)
            {
                string script = String.Format("document.cookie = '{0}={1};expires={2};path=/'", ProviderNameImpl,
                                              ContentItemKey, DateTime.Now.AddMinutes(1).ToUniversalTime());
                ctrl.Attributes["onclick"] = script;
            }
     
            if (ReturnUrlPersistance == ItemKeyPersistanceMode.Cookie)
            {
                string script = String.Format("document.cookie = '{0}={1};expires={2};path=/'", "ReturnUrl",
                                              Context.Server.UrlEncode(Context.Request.RawUrl), DateTime.Now.AddMinutes(1).ToUniversalTime());
                ctrl.Attributes["onclick"] = script;
            }
        }
     
        private ImageGallery.GalleryViewMode galleryViewMode = GalleryViewMode.ListDetails;
    }


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered