Skip to content

Instantly share code, notes, and snippets.

@agehrke
Last active August 29, 2015 14:15
Show Gist options
  • Save agehrke/c9fbef951bd520db7ec6 to your computer and use it in GitHub Desktop.
Save agehrke/c9fbef951bd520db7ec6 to your computer and use it in GitHub Desktop.
Resize media image stream in Sitecore
var mediaItem = GetMediaItemFromSomewhere();
var mediaOptions = new global::Sitecore.Resources.Media.MediaOptions() { MaxWidth = 300 };
var pipelineArgs = new global::Sitecore.Resources.Media.GetMediaStreamPipelineArgs(new global::Sitecore.Resources.Media.MediaData(mediaItem), mediaOptions);
// Run resizing pipeline
var resizeProcessor = new global::Sitecore.Resources.Media.ResizeProcessor();
resizeProcessor.Process(pipelineArgs);
// Copy resized OutputStream to MemoryStream, or use OutputStream.Stream directly
var memoryStream = new System.IO.MemoryStream();
pipelineArgs.OutputStream.CopyTo(memoryStream);
pipelineArgs.OutputStream.Dispose();
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment