Created
November 5, 2013 11:28
-
-
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.…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To me this looks like a lossy optimization. Know of any .NET technologies that can be used for lossless?