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

Forums / Developing with Sitefinity / Getting the thumbnail of an image?

Getting the thumbnail of an image?

3 posts, 0 answered
  1. Ryan
    Ryan avatar
    16 posts
    Registered:
    22 Jan 2014
    02 Apr 2014
    Link to this post

    I set up a custom thumbnail size for one of my image libraries. Since I've done that, the .ChildItemAdditionalInfo is now returning not the regular size image, but a thumbnail at 160x160 which I have NOT asked for. After pissing around for the last hour trying to get this thumbnail I just can't without doing a string replace using my image size name. I can't find anything online for how to achieve this seemingly simple task. What am I missing here?

    var imageId = dynamicTestimonial.GetValue<ContentLink[]>("Image")[0].ChildItemId;
    var image = App.WorkWith().Image(imageId).Get();
    var thumbnailId = image.Thumbnails[0].Id;
    var thumbnailUrl = App.WorkWith().Image(thumbnailId).Get().MediaUrl;

    This returns exception "You are trying to access item that no longer exists. The most probable reason is that it has been deleted by another user."

     This really should not be so difficult. Also, why are there two thumbnails? Is the 160x160 generated by Sitefinity for the backend? If so why are you setting the immediate property to grab my image as the thumbnail I did not ask for or even know exists?

  2. Stacey
    Stacey avatar
    291 posts
    Registered:
    18 Oct 2012
    04 Apr 2014 in reply to Ryan
    Link to this post

    This may not be helpful, but I am not entirely sure what the end result you are going for is.

     First question I have is whether you are using a widget template along with code behind?  If you have  a widget template make sure the ImageAssetField is not set to use "Thumbnail".  

    When I need to get at a specific thumbnail version of the normal image I use the following:

    var thumbnailImage = image.Thumbnails.Where(i => i.Name == "medium").FirstOrDefault();
    primaryImage.ImageUrl = thumbnailImage.ResolveMediaUrl();

    If you just wanted the normal sized image then setting primaryImage.ImageUrl = image.MediaUrl should take care of it.

  3. Ryan
    Ryan avatar
    16 posts
    Registered:
    22 Jan 2014
    04 Apr 2014 in reply to Stacey
    Link to this post

    Stacey,

     I'm using MVC widgets and that's not exactly the way I'm achieving things, but the ResolveMediaUrl() call in fact was the missing piece for me so thanks very much for your help.

3 posts, 0 answered