Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Dynamically Change size of Image in Sitecore?

I created a web service and had imagefield from the sitecore6.6. Now i am want to change the width and height of image dynamically so that i have big image on the fly. There are almost 1000 pictures which require size change . Any help...

like image 938
Sam Avatar asked Apr 23 '13 19:04

Sam


1 Answers

You can use several query string parameters in the url of the image to let Sitecore modify the image. The image has to be a Sitecore Media item.

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 your case you can use for example the ?as=1&w=600 to get the image resized to 600px width.

You can also do this programmatically to set the MediaUrlOptions when creating the mediaUrl:

var mediaOptions = new MediaUrlOptions {AllowStretch = true, Width = 600};
var mediaUrl = MediaManager.GetMediaUrl(mediaItem, mediaOptions);
like image 137
Martijn van der Put Avatar answered Oct 11 '22 02:10

Martijn van der Put