Automatic Thumbnail generation in SharePoint

We’ve got a customer doing a very common thing – and to my surprise, the user experience in SharePoint is pretty frustrating.

The customer has a number of publishing pages, with Images at full size and thumbnail size (for roll-up). So far, so standard. What they’d like, though, is the automatic thumbnailing of images when they’re uploaded to SharePoint. “Easy” I thought. Wrong!

First port of call was the Pictures Library. I know from before that it does thumbnailing, and it stores the thumbnails in hidden _t or _w folders. However, there’s the problem – the _t and _w folders are hidden – that’s the point of the _! So, users trying to pick an image from the Picture Library only get to pick the full size image – even though they can see the thumbnail sized one when they’re picking it!

Bugger.

Next I though I’d look at the publishing ‘Site Images’ library. This isn’t a Pictures library, and though it does show a thumbnail, it doesn’t use hidden folders. So, how does it work? I went and looked at it, and it seems to get the thumbnail from a file in the _Layouts directory called AssetUploader.aspx.

source-of-thumbnail-in-a-library

Okay, so what is in that file?

assetuploaderaspx

Nice. It just inherits from Microsoft.SharePoint.Publishing.Internal.Codebehind.AssetThumbnailerPage. And if you look it up on MSDN – it’s undocumented. Googling finds little about it – this was the best I saw. And it is obfuscated – so Reflector doesn’t show what’s going on.

However, we can see into Microsoft.SharePoint.Publishing.Internal.Codebehind.AssetThumbnailer!

code-of-assetthumbnailer-class

Nice. No sign of any caching or anything there. Certainly, there is a browser cache – but are we regenerating our thumbnail in the image library each time? Honestly, I’m not sure.

So, I don’t think that I fancy doing that. Too many unknowns, and apparently regenerating thumbnails each time they’re requested doesn’t seem very efficient.

What other options are there? Well, an event handler on the list springs to mind – fire when a new image is uploaded, generate a thumbnail, and put it into a picture library. But that’s custom code, which seems a shame.

Edit: I should apologise, seeing as how this post is getting lots of traffic – I’m sorry that I don’t have a pre-built solution. I just thought that people might be interested in how the thumbnails in standard MOSS work, and why I don’t see them as usable for the publishing pages I’m using. Writing an event handler wouldn’t be too hard.

Advertisements
Automatic Thumbnail generation in SharePoint

10 thoughts on “Automatic Thumbnail generation in SharePoint

  1. Excelente! Hablo un poco espanol solo – “Dos cervezas por favor” y “Donde es la ametralladora?” Es una historia larga…

    Like

  2. Hmm. I’d not seen that. I would want to confirm that the thumbnails are thumbnails, though, and not the full size image shown at a smaller scale – that could result in a very heavy page.

    Oh, actually, comment 15 pretty much highlights that problem. That would put me off – Picture libraries are pretty slow, never mind if you’d the full size images to download.

    Neat to see though.

    Like

  3. Hi Andy,

    Your excellent artcile helped my understand the thumbnail process.

    I have a document library that I am uploading invoices stored as tiff’s. I would like to create a jpeg webpreview of each tif as it is uploaded, so I can show the metadata along with the image.

    Would you have any ideas on the code I would need to write and where I would need it to be called?

    Cheers – john

    Like

    1. Hmm. I don’t think that Picture libraries support TIFFs, which I guess is why you’re looking at Document Libraries.

      For those, I’d look at writing an Event Handler (there are lots of articles about them!). In the event handler you’d need to take the file and do the conversion yourself. This could be a bit slow, so best to use the Asynchronous ItemAdded event.

      You’ll then need somewhere to store the thumbnails – another library seems a logical choice.

      Finally, you’ll want to have a Picture column on your list to populate with the URL to that thumbnail file.

      That should work for you!

      Like

  4. umang says:

    so if i add that code in itemupdated and itemadded event handler for doclib i could see images thats what it means?

    my goal is to get image thumnails for doclibs.

    Like

  5. Yes, you could generate your own thumbnails with an event handler. Some consideration might be needed regarding how each image ‘knows’ which thumbnail belongs to it, in case the image is updated.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s