Esempio n. 1
0
        public byte[] OptimizePng(byte[] bytes, int compressionLevel, bool imageQuantizationDisabled)
        {
            var optimizedBytes = bytes;

            if (!imageQuantizationDisabled)
            {
                using (var unQuantized = new Bitmap(new MemoryStream(bytes)))
                {
                    using (var quantized = wuQuantizer.QuantizeImage(unQuantized, 10, 5))
                    {
                        var memStream = new MemoryStream();
                        quantized.Save(memStream, ImageFormat.Png);
                        optimizedBytes = memStream.GetBuffer();
                    }
                }
            }

            if (fileWrapper.FileExists(optiPngLocation))
            {
                var scratchFile = string.Format("{0}\\scratch-{1}.png", configuration.SpritePhysicalPath, Hasher.Hash(bytes));
                try
                {
                    fileWrapper.Save(optimizedBytes, scratchFile);
                    var arg = String.Format(@"-fix -o{1} ""{0}""", scratchFile, compressionLevel);
                    InvokeExecutable(arg, optiPngLocation);
                    optimizedBytes = fileWrapper.GetFileBytes(scratchFile);
                }
                finally
                {
                    fileWrapper.DeleteFile(scratchFile);
                }
            }

            return(optimizedBytes);
        }
Esempio n. 2
0
 public string BuildSpriteUrl(Guid key, byte[] bytes)
 {
     return(string.Format("{0}{1}/{2}-{3}.png", configuration.ContentHost, configuration.SpriteVirtualPath, key.RemoveDashes(), Hasher.Hash(bytes).RemoveDashes()));
 }
Esempio n. 3
0
 public string BuildResourceUrl(Guid key, byte[] bytes, Type type)
 {
     return(BuildResourceUrl(key, Hasher.Hash(bytes).RemoveDashes(), type));
 }
Esempio n. 4
0
 public string BuildResourceUrl <T>(Guid key, byte[] bytes) where T : IResourceType
 {
     return(BuildResourceUrl <T>(key, Hasher.Hash(bytes).RemoveDashes()));
 }
Esempio n. 5
0
        public string BuildSpriteUrl(Guid key, byte[] bytes)
        {
            var url = string.Format("{0}{1}/{2}-{3}.png", configuration.ContentHost, configuration.ResourceAbsolutePath, key.RemoveDashes(), Hasher.Hash(bytes).RemoveDashes());

            return(Registry.UrlTransformer != null
                                   ? Registry.UrlTransformer(RRContainer.Current.GetInstance <HttpContextBase>(), null, url)
                                   : url);
        }