2013, Development Blog, SharePoint, Web Design
SharePoint 2013 Image Renditions (automatic image resizing)
Automated image resizing in SharePoint 2013 is pretty cool! But not all it’s documented to be… I wrote this article to unify the documentation and shed some light on how it all works.
Microsoft’s documentation can be found here.
- https://msdn.microsoft.com/en-us/library/office/jj720398.aspx – SharePoint Design Manager image renditions article
- https://technet.microsoft.com/en-us/library/cc261797.aspx – Information on caching and flushing your cache
- https://technet.microsoft.com/en-us/library/cc770229.aspx – Configure your BlobCache
For Image Renditions to work, you’ll need to activate BlobCache in your SharePoint application’s web.config (so yes, you need your server administrator to do this). Here’s a quick reference. For more information, please see the links above.
Setting up BlobCache
- Locate your web.config in the SharePoint IIS web application (below bullet points were copied from Microsoft TechNet)
- Click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
- In Internet Information Services (IIS) Manager, in the Connections pane, click the plus sign (+) next to the server name that contains the web application, and then click the plus sign next to Sites to view the web application or applications that have been created.
- Right-click the name of the web application for which you want to configure the disk-based cache, and then click Explore. Windows Explorer opens, with the directories for the selected web application listed.
- Right-click web.config, and then click Open.
- If the Windows dialog box appears, select Select a program from a list of installed programs, and then click OK.
- In the Open With dialog box, click Notepad, and then click OK.
- Update this line to be enabled=”true” (instead of false)
true" />
How do I get to Image Renditions configuration?
Site Settings > Image Renditions (under the Look and Feel heading)
For my example, I created up these renditions
- ID: 6, Square Icon, 100px x 100px
- ID: 7, Large Square Image, 300px x 300px
- ID: 8, Rectangular Image, 300px x 100px
Which you can see in this screenshot:
When using RenditionID in the query string, everything works perfectly:
Original Image – /PublishingImages/Doggie.jpg
ID 6 (100 x 100) – /PublishingImages/Doggie.jpg?RenditionID=6
ID 7 (300 x 300) – /PublishingImages/Doggie.jpg?RenditionID=7
ID 8 (300 x 100) – /PublishingImages/Doggie.jpg?RenditionID=8
The quirks with using Width (or Height) only
Microsoft documents that you can use height and width as well, which was unsuccessful in my case, however it appears to work IF your requested width is smaller than one of your rendition presets. So, the following tests assume the same set up described above.
Requesting – /PublishingImages/Doggie.jpg?Width=100 – yields: 100 x 100px (RenditionID 6)
But requesting – /PublishingImages/Doggie.jpg?Width=90 – yields: 100 x 100px (RenditionID 6)
And requesting – /PublishingImages/Doggie.jpg?Width=101 – yields: 300 x 300px (RenditionID 7)
When requesting a width that appears multiple times, SharePoint always selects the first one as default. So requesting – /PublishingImages/Doggie.jpg?Width=300 – yields: 300 x 300px (RenditionID 7)
When you specify Height & Width, SharePoint will render out an image close to what you are requesting, following the same rules outlined above.
Conclusion
I use Height & Width in my web parts, since I have a short list of about 5 different renditions that I plan on using. This allows my contributors to upload any size image in the page roll-ups, and still ensure a zippy page load for those browsing the site.
Why?: To ensure it all works on different environments. These web parts have to function on all developer machines as well as Test, QA and Production environments. RenditionIDs are unique and will differ from environment to environment, so relying on them is simply unreliable.
About Author
Comments are closed