An Interesting Thing About SharePoint Picture Libraries

Tags: SharePoint 2007, SharePoint 2010

I didn’t already know about this 3 weeks ago, but now that I do and have used it to a client’s benefit, I thought it was worth a quick write-up. 

What it is that I didn’t know, you ask?  I didn’t know that a picture within a picture library is available in three different sizes by default, without having to do anything extra.  Just upload one picture, and you can get to it in the following sizes (these sizes vary based on the original picture’s dimensions, so that’s why I don’t have specific sizes listed).  Also, the images that I link to below are coming straight off of www.sharepointnerd.com, which is a SharePoint 2010 site.  I’ve found that this works exactly the same way in SharePoint 2007.

    1. The size in which it was uploaded
      http://www.sharepointnerd.com/Pictures/FIMSyncServiceManagerFirstFullSyncResult.png

    1. A smaller, web-friendly view
      http://www.sharepointnerd.com/Pictures/_w/FIMSyncServiceManagerFirstFullSyncResult_png.jpg

    1. The small, thumbnail size that you see in the “Thumbnail” column
      http://www.sharepointnerd.com/Pictures/_t/FIMSyncServiceManagerFirstFullSyncResult_png.jpg

What you should notice here is simply the differences in the three URLs.  The first one is “normal,” or what we usually expect when linking directly to an image.  The other two, however, are a bit different. 

The web-friendly URL’s format is http://PathToPictureLibrary/_w/NameOfPicture_OriginalFileExtension.jpg…notice the _w there for “web-friendly.”
The thumbnail URL’s format is http://PathToPictureLibrary/_t/NameOfPicture_OriginalFileExtension.jpg…notice the _t there for “thumbnail.”

Even though I only uploaded one picture, I end up with these two additional copies of it in varying sizes. 

You might wonder why SharePoint does this for you.  Quite simply, it does this so that you have a more manageable way to view your pictures when using a web browser.  Instead of seeing all images at their full resolution (3300 x 2865, for example), you see a size that fits “nicely” on your screen and doesn’t force you to scroll across creation to view the rest of the picture.

I’d also like to mention that this actually came in handy at a client.  The client has several very large, high-resolution pictures that they use for internal and external marketing purposes.  Not everyone at the company has image-editing software (though I recommended Paint.NET as a cool free one they could potentially use, which they decided against…you know how these big corporations can be).  Anyway, they needed an easy way for users to be able to download the web-friendly and thumbnail versions of these pictures.  To satisfy their needs, here’s what I ended up doing that worked out very well.

    1. In the picture library I added a "File Extension” single line of text column.  I used a SharePoint Designer workflow to set the value of this column equal to the picture’s file extension (.tif, .jpg, .gif, etc.) so that I could use this column in a calculated column.  This was necessary because SharePoint doesn’t allow you to just use the file extension as part of a calculated column’s formula.

    1. In the picture library I added a “Small JPG” calculated column.  Here’s the formula:

   1:  ="<DIV>

   2:      <a href='RelativeUrlToPictureLibrary/_t/" & Title & "_" & [File Extension] & ".jpg'>

   3:        Download Small

   4:      </a>

   5:    </DIV>"

    1. The output of this formula, meaning the value actually stored in the calculated column, gave me raw HTML similar to this:

   1:  <DIV>

   2:    <a href='RelativeUrlToPictureLibrary/_t/FIMSyncServiceManagerFirstFullSyncResult_png.jpg'>

   3:      Download Small

   4:    </a>

   5:  </DIV>

    1. To make that look nice, I followed Christophe’s guidance here:  http://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html.  It’s one of those “gotta know it” kind of tricks.  I ended up using Christophe’s JavaScript inside a Content Editor Web Part on the page that displays the column that contains the raw HTML.

    1. The output now looks like this:  Download Small

    1. Repeat the steps above for a “Medium JPG” column that points the users to the web-friendly version of the picture.

Now all the users will have to do is right-click the “Download Small” or “Download Medium” links and select “Save picture as…,” which they already know how to do.  The client was very happy with this solution.