Getting the thumbnail of an image?

Posted by Community Admin on 04-Aug-2018 18:58

Getting the thumbnail of an image?

All Replies

Posted by Community Admin on 02-Apr-2014 00:00

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?

Posted by Community Admin on 04-Apr-2014 00:00

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.

Posted by Community Admin on 04-Apr-2014 00:00

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.

This thread is closed