Sitecore Blog: @sitecorejohn blog

Media Options and Query String Parameters in the Sitecore ASP.NET CMS

By John West, May 03, 2011 | Rating:  | Comments (9)

This blog post lists the query string parameters used in URLs of media items in the Sitecore ASP.NET CMS.

The Presentation Component Reference manual on the Sitecore Developer Network (SDN) lists parameters that you can pass to the <sc:image> XSL control, which renders the HTML markup to display the image referenced in a field of type Image. Sitecore adds corresponding parameters to the query string of the URL for the media item.

Some of these query string parameters affect image aspects, such as sizing. Others apply to any type of media, such as language, version, database, and cache functionality.

Here is a list of the supported query string parameters:

  • w: Width in pixels
  • h: Height in pixels
  • mw: Maximum width in pixels
  • mh: Maximum height in pixels
  • la: Language (defaults to context language)
  • vs: Version (defaults to latest version)
  • db: Database name (defaults to context database)
  • bc: Background color (defaults to black)
  • as: Allow stretch (as=1)
  • sc: Scale by floating point number (sc=.25 = 25%)
  • thn: Thumbnail (thn=1)
  • dmc: Disable media caching, both retrieval and storage (dmc=1)

In general, avoid constructing URLs using these query string parameters explicitly. For example, use the Sitecore.Data.Items.Item.Appearance.Icon property to retrieve the icon, the Sitecore.Resources.Media.MediaManager.GetThumbnailUrl() method to retrieve the URL, or the Sitecore.Resources.Media.MediaManager.GetMediaUrl() method with the Sitecore.Resources.Media.MediaUrlOptions class to construct the URL programatically. Remember to use something like the Sitecore.StringUtil.EnsurePrefix() method to ensure that media URLs begin with a slash (/) rather than a tilde (~). Media URLs that begin with this character can result in multiple URLs for media items and sooner exceed IIS path length limits. You can download some sample code that shows these techniques.

Tags: API, Architecture

Comments

  • Very useful information. I found few more.
    What does it mean if my url contains querystring as
    &mo=preview&we=1.

    What is the purpose of sc_wede=1 in cookie

    - Shri Shri
    June 07, 2011 at 12:25 AM

  • I'd take a guess that we or wede is web edit and mo is mode.

    - mark stiles
    November 29, 2011 at 11:42 AM

  • Check out the Shared Source Module 'Image Cropper' by Igloo Digital. It allows a crop=1 parameter to trim the image so you don't get the letter boxing background.
    http://blog.igloo.com.au/?p=3431

    - Sean Holmesby
    January 25, 2012 at 10:11 PM

  • There is another parameter which can be used to convert the image in grayscale : gray=1

    - christophe Goasduff
    December 06, 2012 at 2:57 AM

  • http://marketplace.sitecore.net/en/Modules/ImageProcessor_Module.aspx

    - John West
    March 01, 2013 at 11:11 AM

  • // bc: Background color (defaults to black)
    Can't we change this default colour to "White"?

    - Chackrapani Wickramarathne
    October 02, 2013 at 9:25 PM

  • My thought would be to try overriding the ResizeProcessor processor in the getMediaStream pipeline to set this to white if it is black (or maybe null). If you can check for null, that would be better because you might in some cases want black. If you cannot check for null and may need black, maybe disable your logic if bc appears in the query string.

    - John West
    October 08, 2013 at 11:11 AM

  • http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2013/10/Set-Default-Background-Color-for-Resizing-Images-with-the-Sitecore-ASPNET-CMS.aspx

    - John West
    October 08, 2013 at 11:58 AM

  • http://sitecorejunkie.com/2013/10/21/specify-the-maximum-width-of-images-uploaded-to-the-sitecore-media-library/

    - John West
    October 21, 2013 at 8:21 PM

*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
 
Captcha

 
*{0} must be filled in.