Skip to content

Instantly share code, notes, and snippets.

@leethomascook
Created November 5, 2013 11:28
Show Gist options
  • Save leethomascook/7317704 to your computer and use it in GitHub Desktop.
Save leethomascook/7317704 to your computer and use it in GitHub Desktop.
Automatic sitecore image compression. First install this nuget package: Run: Install-Package nQuant Then add to your pipeline: <getMediaStream> <processor type="Sitecore.Resources.Media.ThumbnailProcessor, Sitecore.Kernel" /> <processor type="Sitecore.Resources.Media.ResizeProcessor, Sitecore.Kernel" /> <processor type="Sitecore.Resources.Media.…
public class ImageCompressionProcessor
{
public void Process(GetMediaStreamPipelineArgs args)
{
MediaStream outputStream = args.OutputStream;
if (outputStream == null)
return;
var bitmap = new Bitmap(Image.FromStream(outputStream.Stream));
var memoryStream = new MemoryStream();
var quantizer = new WuQuantizer();
using (var quantized = quantizer.QuantizeImage(bitmap))
{
quantized.Save(memoryStream, ImageFormat.Jpeg);
}
args.OutputStream = new MediaStream(memoryStream, "jpg",args.MediaData.MediaItem);
}
}
@jdylanmc
Copy link

To me this looks like a lossy optimization. Know of any .NET technologies that can be used for lossless?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment