Resizing Thumbnails in the Asset Library

Just been working on a project to create a searchable archive of images.  The SharePoint 2010 Asset Library features a very nice automatic thumbnail generation feature, which works even if the source file is something that a web browser doesn’t traditionally handle, like a .TIF.  The Asset Library also has a very nice preview feature, which is available if you upload an image and then rollover it with the mouse.

My idea was to present this thumbnail to the users when they were searching.  The images are scanned pages from books, so ensuring that they had the right page would be important.  Solution seemed obvious, present the auto-generated thumbnail as a sort of preview (the full sized image was far too big, and besides, would have a bandwidth overhead if I resized them.

The problem was that the thumbnails were, by default, quite small and the detail that the users needed to verify they had the right image was too small, so I wondered if it were possible to increase the default thumbnail size.

This being SharePoint, the answer is a) of course, b) tricky to find and c) really easy to implement.

First up, the Asset Library and the Picture Library are sort of the same, but not.  This post has some excellent pointers on the differences, especially if you are migrated.  However, the class we are dealing with is SPPictureLibrary.

SPPictureLibrary has several properties.  First off, you will immediately jump on ThumbnailSize.  This would be a mistake.  When you upload an image into an Asset Library, it shows a thumbnail preview.  The size of this thumbnail preview is determined by the ThumbnailSize property.

The Preview image shown by the rollover is not controlled by the ThumbnailSize property.  The preview size is controlled by two properties, WebImageWidth and WebImageHeight. By default for a picture library, these values are set to 320px and 200px respectively.  You can update the values using a console app or Powershell script – I’m not sure whether you could do it in a List Definition as I have’t tried it.  The following script will set the Preview to 1000px high or 750px wide, which ever is the smaller for the image.  I don’t think it scales images up if they are smaller than these parameters.

$url = "%YOUR_URL%"
$listName = "%YOUR_LIBRARY_NAME%"
$web = Get-SPWeb $url
$list = web.Lists[$listName]
$list.WebImageWidth = 1000
$list.WebImageHeight = 750
$list.Update()
$web.Dispose()

Try to keep the ratio between Width and Height to 4:3  (so 320/200, 640/400, 1000/750).  The standard Preview view on the mouse rollover will resize the image to keep within its internal boundaries and therefore won’t “break” any layout.

Advertisements

Posted on May 22, 2013, in SharePoint and tagged , , , . Bookmark the permalink. 2 Comments.

  1. Curious how do you change the default thumbnail size before you hover over?

  2. Without having a development machine nearby to check, with SPPictureLibrary, you can use $list.ThumbnailSize – but the value is the height or width, whichever is the longer.

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.sppicturelibrary.thumbnailsize(v=office.12).aspx

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: