private void WriteToCache(IMagickImage image, string cacheFileName) { string tempFile = DetermineTempFileName(); try { image.Write(tempFile); MagickFormatInfo formatInfo = MagickNET.GetFormatInformation(_scriptResolver.OutputFormat); if (HandlerHelper.CanOptimize(Settings, formatInfo)) { OptimizeFile(tempFile); } MoveToCache(tempFile, cacheFileName); } finally { if (File.Exists(tempFile)) { File.Delete(tempFile); } } }
public void Test_CanOptimize() { string config = @" <magick.net.web canCreateDirectories=""false"" cacheDirectory=""c:\cache""> <optimization enabled=""false""/> </magick.net.web>"; MagickWebSettings settings = TestSectionLoader.Load(config); bool canCompress = HandlerHelper.CanOptimize(settings, JpgFormatInfo); Assert.IsFalse(canCompress); }