Skip to main content

Cloud

Deep Dive Part 2: Image Renditions (SharePoint 2013)

Rendering & Cache
Part 1 of this post describes where the definitions for the image renditions are stored and how versioning is handled. This post will describe how those renditions are applied to an image and how those images are stored. If you are the curious kind and always want to know what goes on behind the scenes, you will probably love this.
Note: There might some changes in the beta version, but the general working explained here should be the same. I will edit this post once I verify the working in the Beta.
Before I work through the details here are some pre-requisites:

  • Blob cache should be enabled.
  • Any image that you want to apply a rendition to should be published, otherwise the image will not be added to the cache. You will be able to see the rendition but it wont be delivered to you from the blob cache.

To apply a rendition to an image:
1. Add an image to a publishing page
2. Select the Design Tab
3. Click on Pick Rendition and select a rendition.
clip_image002
When you select a rendition, SharePoint will add a query string parameter called “RenditionID” to the Url of the image. This is the same ID you will find in the PublishingImageRenditions.xml.
clip_image004
The browser is requesting the image with a query string parameter. SharePoint handles the request in the following way.
When the HttpRuntime passes the request to the registered HttpModules:
1. The PublishingHttpModule picks up the request and creates a BlobCache object.
2. RewriteUrl method on the BlobCache object is invoked. (This handles how the specified resource is to be processed)
3. The RewriteUrl method does some processing and then calls the GetGeneratedRequestInfo method on the BlobGeneratedInfo class.
4. The GetGeneratedRequestInfo method in turn calls the GetImageRenditionInfo method on the ImageRenditionGeneratedInfo class. (This gathers information about the rendition for that image and returns it)
5. The GetImageRenditionInfo method checks if the file extension is a valid image extension and then calls GetRenditionForRequest method to get the rendition that has been requested using the query string parameter (RenditionID)
6. The GetRenditionForRequest calls the GetSiteRenditions method which returns the renditions defined in the PublishingImageRenditions.xml and in the form of an object of the type SiteImageRenditions. The SiteImageRenditions objects contains the collection of the renditions defined in the xml.
7. The GetRenditionForRequest method now has all the renditions defined and hence can filter out the rendition that was used for the requested image. (Defined by the query string parameter “RenditionID”).
8. The GetImageRenditionInfo method now returns a new object (type:ImageRenditionGeneratedInfo) with the just found rendition back to ReWriteURL method of the BlobCache object. (BlobGeneratedInfo is an abstract class, the ImageRenditionGeneratedInfo inherits and implements the BlobGeneratedInfo class)
9. The RewriteUrl method now invokes the GenerateLocalPath method on the ImageRenditionGeneratedInfo object. This method creates the path and name of the file that will be added the blob cache.

1. The format of the file: “Path””RenditionID”_”RenditionVersion”

10. The RewriteUrl method now does a couple of checks and then calls FetchItemFromWss method which is responsible for creating the file in the blob cache directory.
11. The FetchItemFromWss method checks if the file is published and then goes ahead and calls the CreateFile method.
12. The CreateFile method then calls the GenerateFile method on the ImageRenditionGeneratedInfo object.
13. The GenerateFile method in turn calls the GenerateRendition method on the ImageRendition class which actually resizes the image / crops it and then returns a stream of the new image.

1. So where does it get the cropping values from ?? These were not defined in the xml file.
2. When a rendition is getting generated using Edit Renditions screen, the cropping values are actually stored in the property bag of the image file itself.
3. The property name is of the following format : “PublishingImageRendition” + RenditionID. E.g. PublishingImageRendition1 , PublishingImageRendition2 ,etc.
4. The value of the property has a specific format: RenditionVersion;SourceImageWidth;SourceImageHeight;CropStartX;CropStartY;CropWidth;CropHeight;

14. The CreateFile method now flushes the stream to the file system. (Actually creates a temp file and then moves it to the actual location)
15. We finally have the file in cache.
There are a lot more checks / conditions that are taken care of and I have emitted those details in this description.
To generate a rendition which only displays a certain portion of the image, follow the steps below:
1. Add an image to the page
2. Select the image
3. Click on the Design Tab
4. Click on Pick Rendition
5. Click on Edit Renditions
clip_image006
6. Click on “Click to Change”
clip_image008
clip_image010
Now you can drag/drop/move the box to define the exact area that you want to use. Once you click on save, the rendition is saved along with its settings.
This can also be done directly from the library which contains those images.
That’s all to it.

Thoughts on “Deep Dive Part 2: Image Renditions (SharePoint 2013)”

  1. Pingback: Deep Dive Part 1: Image Renditions ( SharePoint 2013 ) | Microsoft Enterprise Technologies

  2. Pingback: What's New in SharePoint 2013? Let's ask the experts... | Microsoft Enterprise Technologies

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Amol Ajgaonkar

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram