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

Forums / Designing with Sitefinity / Different Thumbnails For Image Gallery In Lightbox Mode

Different Thumbnails For Image Gallery In Lightbox Mode

5 posts, 0 answered
  1. gohigher
    gohigher avatar
    25 posts
    Registered:
    24 Nov 2008
    12 Apr 2010
    Link to this post
    Is there a way to specify different images that are not the larger images of the thumbnails for the image gallery in Lightbox mode? Our clients has images of different sizes and we would like to the thumbnails to display so that they appear crisp and not distorted. Then when you click it on it displays the actual image in full resolution.
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    13 Apr 2010
    Link to this post
    Hi Jamal,

    Thank you for using our services.

    The thumbs that are generated during upload. When you upload an image through the backend UI we generate the thumbnail at run time.You can add a thumbnailResizeSettings configuration element to the cmsEngine configuration settings to set the settings which will be taken when the ImagesHelper class generates thumbnails for your images uploaded. Sample bellow:

    Copy Code
    <cmsEngine  defaultProvider="Generic_Content"  >
    <thumbnailResizeSettings compositingQuality="HighQuality" interpolationMode="HighQualityBicubic" smoothingMode="HighQuality">
    </thumbnailResizeSettings>
          <providers>
              <clear/>


    You can check out the MSDN Library for the different values you can use for each property:
    CompositingQuality Enumeration
    InterpolationMode Enumeration
    SmoothingMode Enumeration

    You can get all images in image libraries and generate new thumbnails for them using something like this:

    Copy Code
    LibraryManager libraryManager = new  LibraryManager();
    IList imageLibraries = libraryManager.GetAllLibraries("Image", true);
    foreach(ILibrary library in imageLibraries)
    {
        foreach (IContent contentItem in library.GetItems())
        {
            System.Drawing.Image imagethmb = ImagesHelper.GenerateThumbnail(250,250, System.Drawing.Image.FromStream(new MemoryStream((byte[])contentItem.Content)));
            MemoryStream ms = new MemoryStream();
            //get format from extension
            imagethmb.Save(ms, ImageFormat.Jpeg);
            byte[] tnumbData = ms.ToArray();
            IThumbnail newThumb = libraryManager.AddThumbnail(contentItem, tnumbData, contentItem.MimeType.ToString(), contentItem.GetMetaData("Extension").ToString(), contentItem.GetMetaData("Title").ToString(), true);
            StagedContent stagedCnt = (StagedContent)libraryManager.GetStagedContent(contentItem.ID);
            if (stagedCnt.Thumbnails.Count > 0)
                stagedCnt.Thumbnails.Clear();
            stagedCnt.Thumbnails.Add(newThumb);
            libraryManager.SaveContent(stagedCnt, ContentStatus.Published);
        }
    }

    Otherwise you need to create a custom module that inherits from Images and Documents and implement custom method for saving the items and generating the thumbnails. You could use standard ASP.NET classes as System.Drawing.Graphics, System.Drawing.Image, Bitmap.Bitmap.

    Sincerely yours,
    Radoslav Georgiev
    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.
  3. OC
    OC avatar
    129 posts
    Registered:
    17 Nov 2004
    26 Oct 2010
    Link to this post
    IThumbnail newThumb = libraryManager.AddThumbnail(contentItem, tnumbData, contentItem.MimeType.ToString(), contentItem.GetMetaData("Extension").ToString(), contentItem.GetMetaData("Title").ToString(), true);

    This line only produces an " Object reference not set to an instance of an object." error when I try running this code.

    Any ideas? Running 3.7 SP4 (.net 3.5).

    OC
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 Oct 2010
    Link to this post
    Hi Mutantmannen,

    You use an object that is null in the context you are executing the code. You could use Visual Studio and debug the code to see which object is null.

    Sincerely yours,
    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
  5. OC
    OC avatar
    129 posts
    Registered:
    17 Nov 2004
    27 Oct 2010
    Link to this post
    There is no metadata called "Title". It should be "Name" instead.

    OC
Register for webinar
5 posts, 0 answered