public void SigmoidalTest() { double[] alpha = { 1, 2, 3, 4 }; double[] beta = { 0 , 5000, 20000, 30000, 40000, 65000 }; MagickWandEnvironment.Genesis(); foreach(var file in _files) { using(var wand = new MagickWand(file)) { foreach(var a in alpha) { foreach(var b in beta) { using(var tmp = wand.Clone()) { tmp.SigmoidalContrastImage(true, a, b); WriteImage("sigmoidal", file, new string[] { a.ToString(), b.ToString() }, tmp); } } } } } MagickWandEnvironment.Terminus(); }
public void ContrastTest() { double[] alpha = { 0, .5, 1, 1.1 }; double[] beta = { 0 , 5000, 20000, 30000, 40000, 65000 }; MagickWandEnvironment.Genesis(); foreach(var file in _files) { using(var wand = new MagickWand(file)) { using(var tmp = wand.Clone()) { tmp.ContrastImage(true); WriteImage("contrast", file, new string[] { "1" }, tmp); tmp.ContrastImage(true); WriteImage("contrast", file, new string[] { "2" }, tmp); tmp.ContrastImage(true); WriteImage("contrast", file, new string[] { "3" }, tmp); } } } MagickWandEnvironment.Terminus(); }
public uint GetOptimalQuality(MagickWand wand) { var tmp = $"{Path.GetTempFileName()}.jpg"; try { using(var tmpWand = wand.Clone()) { tmpWand.CompressionQuality = MAX_QUALITY; wand.WriteImage(tmp, true); } var opts = new ImgminOptions { ErrorThreshold = 0.08 }; var imgmin = new Imgmin(opts); var result = imgmin.Minify(tmp, tmp); if(!_quiet) { Console.WriteLine(result.StandardOutput); } // the following has not been reliable, so figure out the // quality based on opening the tmp file. //return Convert.ToUInt32(result.StatsAfter.Quality); using(var qualWand = new MagickWand(tmp)) { return qualWand.ImageCompressionQuality; } } finally { File.Delete(tmp); } }
public void ContrastStretchTest() { double[] black = { 0, 100, 1000, 2000 }; double[] white = { 0, 50000, 60000, 65000 }; MagickWandEnvironment.Genesis(); foreach(var file in _files) { using(var wand = new MagickWand(file)) { foreach(var b in black) { foreach(var w in white) { using(var tmp = wand.Clone()) { tmp.ContrastStretchImage(b, w); WriteImage("contrast_stretch", file, new string[] { b.ToString(), w.ToString() }, tmp); } } } } } MagickWandEnvironment.Terminus(); }
public void BrightnessContrastTest() { double[] brightness = { 0, 10, 25 }; double[] contrast = { 0, 10, 25 }; MagickWandEnvironment.Genesis(); foreach(var file in _files) { using(var wand = new MagickWand(file)) { foreach(var b in brightness) { foreach(var c in contrast) { using(var tmp = wand.Clone()) { tmp.BrightnessContrastImage(b, c); WriteImage("brightness_contrast", file, new string[] { b.ToString(), c.ToString() }, tmp); } } } } } MagickWandEnvironment.Terminus(); }
public void ModulateTest() { double[] brightness = { 50, 100, 150 }; double[] saturation = { 0, 100, 120, 150 }; MagickWandEnvironment.Genesis(); foreach(var file in _files) { using(var wand = new MagickWand(file)) { foreach(var b in brightness) { foreach(var s in saturation) { using(var tmp = wand.Clone()) { tmp.ModulateImage(b, s, 300); // 300 = no rotation WriteImage("modulate", file, new string[] { b.ToString(), s.ToString() }, tmp); } } } } } MagickWandEnvironment.Terminus(); }
public void LevelTest() { double[] black = { 0, 100, 1000, 2000 }; double[] white = { 0, 50000, 60000, 65000 }; MagickWandEnvironment.Genesis(); foreach(var file in _files) { using(var wand = new MagickWand(file)) { foreach(var b in black) { foreach(var w in white) { using(var tmp = wand.Clone()) { tmp.LevelImage(b, 1, w); // 1 = no gamma WriteImage("level", file, new string[] { b.ToString(), w.ToString() }, tmp); } } } } } MagickWandEnvironment.Terminus(); }
public void TestNightOptimizations() { MagickWandEnvironment.Genesis(); using(var mw = new MagickWand("nighttest.jpg")) { using(var mw2 = mw.Clone()) { mw2.AutoGammaImage(); Write(mw2, "night_AutoGammaImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.AutoLevelImage(); Write(mw2, "night_AutoLevelImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.LinearStretchImage(2, 98); Write(mw2, "night_LinearStretchImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.NormalizeImage(); Write(mw2, "night_NormalizeImage.jpg"); } } MagickWandEnvironment.Terminus(); }
public void TestBasicWandMethods() { MagickWandEnvironment.Genesis(); using(var pw = new PixelWand()) using(var mw = new MagickWand("test.jpg")) { pw.Red = 200; using(var mw2 = mw.Clone()) { mw2.AdaptiveBlurImage(5, 2); Write(mw2, "AdaptiveBlurImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.AdaptiveResizeImage(320, 212); Write(mw2, "adaptiveResizeImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.AdaptiveSharpenImage(20, 12); Write(mw2, "AdaptiveSharpenImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.AdaptiveThresholdImage(20, 12, 2); Write(mw2, "AdaptiveThresholdImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.AddNoiseImage(NoiseType.PoissonNoise); Write(mw2, "AddNoiseImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.AutoGammaImage(); Write(mw2, "AutoGammaImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.AutoLevelImage(); Write(mw2, "AutoLevelImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.AutoOrientImage(); Write(mw2, "AutoOrientImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.BlurImage(10, 2); Write(mw2, "BlurImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.BorderImage(pw, 10, 10); Write(mw2, "BorderImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.BrightnessContrastImage(30, 20); Write(mw2, "BrightnessContrastImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.CharcoalImage(30, 20); Write(mw2, "CharcoalImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ChopImage(30, 20, 0, 0); Write(mw2, "ChopImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ClampImage(); Write(mw2, "ClampImage.jpg"); } /* using(var mw2 = mw.Clone()) { mw2.ClipImage(); Write(mw2, "ClipImage.jpg"); } */ using(var mw2 = mw.Clone()) { mw2.ContrastImage(true); Write(mw2, "ContrastImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ContrastStretchImage(2, 98); Write(mw2, "ContrastStretchImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.CropImage(30, 20, 0, 0); Write(mw2, "CropImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.CycleColormapImage(4); Write(mw2, "CycleColormapImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.DeskewImage(40); Write(mw2, "DeskewImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.DespeckleImage(); Write(mw2, "DespeckleImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.EdgeImage(2); Write(mw2, "EdgeImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.EmbossImage(12, 2); Write(mw2, "EmbossImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.EnhanceImage(); Write(mw2, "EnhanceImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.EqualizeImage(); Write(mw2, "EqualizeImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.EvaluateImage(MagickEvaluateOperator.CosineEvaluateOperator, 4); Write(mw2, "EvaluateImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ExtentImage(5, 5, 0, 0); Write(mw2, "ExtentImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.FlipImage(); Write(mw2, "FlipImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.FlopImage(); Write(mw2, "FlopImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.FrameImage(pw, 10, 10, 4, 4); Write(mw2, "FrameImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.GammaImage(3); Write(mw2, "GammaImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.GaussianBlurImage(12, 3); Write(mw2, "GaussianBlurImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ImplodeImage(12); Write(mw2, "ImplodeImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.LevelImage(2, 2.3, 98); Write(mw2, "LevelImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.LinearStretchImage(2, 98); Write(mw2, "LinearStretchImage.jpg"); } /* using(var mw2 = mw.Clone()) { mw2.LiquidRescaleImage(320, 212, 2, 2); Write(mw2, "LiquidRescaleImage.jpg"); } */ using(var mw2 = mw.Clone()) { mw2.LocalContrastImage(8, 4); Write(mw2, "LocalContrastImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.MagnifyImage(); Write(mw2, "MagnifyImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.MinifyImage(); Write(mw2, "MinifyImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ModulateImage(2, 3, 4); Write(mw2, "ModulateImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.MotionBlurImage(12, 3, 45); Write(mw2, "MotionBlurImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.NegateImage(true); Write(mw2, "NegateImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.NormalizeImage(); Write(mw2, "NormalizeImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.OilPaintImage(8); Write(mw2, "OilPaintImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.OptimizeImageTransparency(); Write(mw2, "OptimizeImageTransparency.jpg"); } using(var mw2 = mw.Clone()) { mw2.PosterizeImage(64, true); Write(mw2, "PosterizeImage.jpg"); } /* using(var mw2 = mw.Clone()) { mw2.ProfileImage(); Write(mw2, "ProfileImage.jpg"); } */ using(var mw2 = mw.Clone()) { mw2.QuantizeImage(64, ColorspaceType.sRGBColorspace, 12, true, false); Write(mw2, "QuantizeImage.jpg"); } /* using(var mw2 = mw.Clone()) { mw2.RaiseImage(320, 212, 4, 4, true); Write(mw2, "RaiseImage.jpg"); } */ using(var mw2 = mw.Clone()) { mw2.RandomThresholdImage(5, 80); Write(mw2, "RandomThresholdImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ResampleImage(96, 96, FilterTypes.Lanczos2SharpFilter, 1); Write(mw2, "ResampleImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ResizeImage(320, 212, FilterTypes.Lanczos2Filter, 2); Write(mw2, "ResizeImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.RollImage(4, 4); Write(mw2, "RollImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.RotateImage(pw, 45); Write(mw2, "RotateImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.RotationalBlurImage(45); Write(mw2, "RotationalBlurImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.SampleImage(320, 212); Write(mw2, "SampleImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ScaleImage(320, 212); Write(mw2, "ScaleImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.SegmentImage(ColorspaceType.sRGBColorspace, false, 5, 2); Write(mw2, "SegmentImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.SelectiveBlurImage(8, 2, 4); Write(mw2, "SelectiveBlurImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.SepiaToneImage(52428); Write(mw2, "SepiaToneImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ShadeImage(true, 8, 8); Write(mw2, "ShadeImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ShadowImage(8, 4, 0, 0); Write(mw2, "ShadowImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.SharpenImage(8, 4); Write(mw2, "SharpenImage.jpg"); } /* using(var mw2 = mw.Clone()) { mw2.ShaveImage(320, 212); Write(mw2, "ShaveImage.jpg"); } */ using(var mw2 = mw.Clone()) { mw2.ShearImage(pw, 12, 12); Write(mw2, "ShearImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.SketchImage(12, 4, 45); Write(mw2, "SketchImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.SolarizeImage(5); Write(mw2, "SolarizeImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.SpreadImage(5); Write(mw2, "SpreadImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.SwirlImage(5); Write(mw2, "SwirlImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ThresholdImage(5); Write(mw2, "ThresholdImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.ThumbnailImage(320, 212); Write(mw2, "ThumbnailImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.TintImage(pw, pw); Write(mw2, "TintImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.TrimImage(8); Write(mw2, "TrimImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.UnsharpMaskImage(8, 2, 3, 4); Write(mw2, "UnsharpMaskImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.VignetteImage(8, 90, 3, 4); Write(mw2, "VignetteImage.jpg"); } using(var mw2 = mw.Clone()) { mw2.WaveImage(8, 12); Write(mw2, "WaveImage.jpg"); } } MagickWandEnvironment.Terminus(); }
public async Task<ProcessingResult> ProcessPhotoAsync(string filename) { var result = new ProcessingResult(); var jpgName = Path.ChangeExtension(filename, ".jpg"); var origPath = _pathHelper.GetSourceFilePath(filename); var srcPath = _pathHelper.GetScaledLocalPath(SourceTarget.ScaledPathSegment, filename); result.ExifData = await _exifReader.ReadExifDataAsync(origPath); // always keep the original in the source dir File.Move(origPath, srcPath); result.Source = new ProcessedPhoto { Target = SourceTarget, LocalFilePath = srcPath, WebFilePath = _pathHelper.GetScaledWebFilePath(SourceTarget.ScaledPathSegment, filename) }; using(var wand = new MagickWand()) { if(_rawConverter.IsRawFile(srcPath)) { result.RawConversionResult = await _rawConverter.ConvertAsync(srcPath); wand.ReadImage(result.RawConversionResult.OutputFile); File.Delete(result.RawConversionResult.OutputFile); } else { wand.ReadImage(srcPath); } result.Source.Height = wand.ImageHeight; result.Source.Width = wand.ImageWidth; wand.AutoOrientImage(); wand.StripImage(); using(var optWand = wand.Clone()) { result.OptimizationResult = _optimizer.Optimize(optWand); // get the best compression quality for the optimized image // (best => smallest size for negligible quality loss) result.CompressionQuality = (short)_qualitySearcher.GetOptimalQuality(optWand); result.Xs = ProcessTarget(wand, optWand, result.CompressionQuality, XsTarget, jpgName); result.Sm = ProcessTarget(wand, optWand, result.CompressionQuality, SmTarget, jpgName); result.Md = ProcessTarget(wand, optWand, result.CompressionQuality, MdTarget, jpgName); result.Lg = ProcessTarget(wand, optWand, result.CompressionQuality, LgTarget, jpgName); result.Print = ProcessTarget(wand, optWand, result.CompressionQuality, PrintTarget, jpgName); } } return result; }