public async Task<ProcessingResult> ProcessPhotoAsync(string filename) { using(var wand = new MagickWand()) { var srcFile = _pathHelper.GetSourceFilePath(filename); if(_rawConverter.IsRawFile(srcFile)) { var conversionResult = await _rawConverter.ConvertAsync(srcFile); wand.ReadImage(conversionResult.OutputFile); File.Delete(conversionResult.OutputFile); } else { wand.ReadImage(srcFile); } wand.AutoOrientImage(); wand.AutoLevelImage(); wand.StripImage(); var path = Path.Combine(Path.GetDirectoryName(srcFile), "review", $"{Path.GetFileNameWithoutExtension(filename)}.jpg"); wand.WriteImage(path, true); } return null; }
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; }