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 void Resize() { var file = "test3.jpg"; MagickWandEnvironment.Genesis(); using(var mw = new MagickWand()) { mw.ReadImage("test.jpg"); mw.ResizeImage(120, 100, FilterTypes.LanczosFilter, 1); mw.WriteImage(file, true); Assert.True(File.Exists(file), "scaled image not created"); } using(var mw = new MagickWand(file)) { Assert.True(mw.ImageWidth == 120, "width does not match the expected size"); Assert.True(mw.ImageHeight == 100, "height does not match the expected size"); } File.Delete(file); MagickWandEnvironment.Terminus(); }
public void SaveResizedImage(int newWidth, string outPath) { CreateDirectoryForFile(outPath); using (MagickWand wand = new MagickWand()) { wand.ReadImage(filename); wand.TransformImage("", newWidth.ToString()); wand.WriteImage (outPath); } }
public Image(string filename) { this.filename = filename; using (MagickWand wand = new MagickWand()) { wand.ReadImage(filename); this.width = (int)wand.ImageWidth; this.height = (int)wand.ImageHeight; } }
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; }
public void SaveResizedImage(int newWidth, int newHeight, string outPath) { CreateDirectoryForFile(outPath); using (MagickWand wand = new MagickWand()) { wand.ReadImage(filename); if (width > newWidth && height > newHeight) { wand.ResizeImage((uint)newWidth, (uint)newHeight); } else { // XXX: Make a new image that's newwidth by newheight // and center old image in it } wand.WriteImage (outPath); } }
public void TestWrapperAndStringQueryFuncs() { MagickWandEnvironment.Genesis(); using(var mi = new MagickWand()) { mi.ReadImage(TestHelper.TEST_FILE); var list = mi.GetImageProperties(string.Empty); Assert.True(list != null, "the list should not be null"); Assert.True(list.Count > 0, "there should be more than 1 profile"); foreach(var item in list) { Console.WriteLine($"profile: {item}"); } } MagickWandEnvironment.Terminus(); }