private MagickImage ExecuteMethod1(MagickImage first, MagickImage second) { using (var first_0 = first.Clone()) { first_0.Composite(second, CompositeOperator.Multiply); first_0.Modulate(Brightness, Saturation, (Percentage)100); using (var third = first.Clone()) { third.ColorSpace = ColorSpace.Gray; using (var fourth = third.Clone()) { fourth.Negate(); fourth.Blur(0, _edgeWidth); var result = third.Clone(); result.Composite(fourth, CompositeOperator.ColorDodge); result.Evaluate(Channels.All, EvaluateOperator.Pow, EdgeAmount); result.Threshold(_edgeThreshold); result.Statistic(StatisticType.Median, 3, 3); result.Composite(first_0, CompositeOperator.Multiply); return(result); } } } }
public override void Convert() { MagickImage image = Converter.MyPreviewImage; using (MagickImage color = new MagickImage(image.Clone())) { int length = Math.Max(color.Height, color.Width) + 2; length -= (length % 4); color.Format = MagickFormat.Png32; color.Extent(length, length, Gravity.Center, new MagickColor(0, 0, 0, 0)); color.ColorAlpha(MagickColors.None); color.Format = MagickFormat.Dds; color.Settings.SetDefine(MagickFormat.Dds, "compression", "dxt5"); //dxt1, dxt5, none color.Settings.SetDefine(MagickFormat.Dds, "fast-mipmaps", "true"); color.Settings.SetDefine(MagickFormat.Dds, "mipmaps", "10"); color.Settings.SetDefine(MagickFormat.Dds, "cluster-fit", "true"); color.Write(MyImagePath + "_c.dds"); } if (GenerateMask) { using (MagickImage alpha = new MagickImage(image.Clone())) { int length = Math.Max(alpha.Height, alpha.Width) + 2; length -= (length % 4); alpha.Format = MagickFormat.Png; alpha.Extent(length, length, Gravity.Center, new MagickColor(0, 0, 0, 0)); alpha.Grayscale(); foreach (Pixel p in alpha.GetPixels()) { MagickColor c = (MagickColor)p.ToColor(); p.SetChannel(0, c.A); p.SetChannel(1, 0); } alpha.Format = MagickFormat.Dds; alpha.Settings.SetDefine(MagickFormat.Dds, "compression", "dxt5"); //dxt1, dxt5, none alpha.Settings.SetDefine(MagickFormat.Dds, "fast-mipmaps", "true"); alpha.Settings.SetDefine(MagickFormat.Dds, "mipmaps", "10"); alpha.Settings.SetDefine(MagickFormat.Dds, "cluster-fit", "true"); alpha.Write(MyImagePath + "_a.dds"); } } }
private static MagickImage CreateRolled(MagickImage image, int thickness) { MagickImage rolled = image.Clone(); rolled.Roll(thickness, 0); return(rolled); }
private string Process() { try { using (MagickImage srcMagickImage = new MagickImage(_inputFilePath)) { using (MagickImage clonedImage = (MagickImage)srcMagickImage.Clone()) { using (MagickImage beforeImage = new MagickImage(new MagickColor(127, 187, 227, 51), srcMagickImage.Width, srcMagickImage.Height)) { clonedImage.BrightnessContrast(new Percentage(0), new Percentage(10)); clonedImage.Modulate(new Percentage(100), new Percentage(130), new Percentage(100)); clonedImage.Composite(beforeImage, CompositeOperator.Overlay); clonedImage.Write(_outputFilePath); return(string.Empty); } } } } catch (Exception e) { return(e.Message); } }
public override void Apply(MagickImage image) { if (Radius == 0 && Threshold == 0) { return; } var mask = (MagickImage)image.Clone(); mask.ColorSpace = ColorSpace.Gray; mask.ReduceNoise(10); mask.Threshold(new Percentage(Threshold)); // mask.Sharpen(); // mask.Blur(5, 5); mask.Negate(); mask.Write(Path.Combine(Paths.ResourcesPath(Engine.Engine.project), "Mask.png")); image.SetWriteMask(mask); image.Blur(0, Radius); image.RemoveWriteMask(); // Debug.Log(Path.Combine(Paths.ResourcesPath(Engine.Engine.project))); image.Write(Path.Combine(Paths.ResourcesPath(Engine.Engine.project), "custom.png")); // var clone = image.Clone(); // clone.SelectiveBlur(0, Radius, new Percentage(Threshold)); // clone.Write(Path.Combine(Paths.ResourcesPath(Engine.Engine.project), "selective.png")); }
public static BitmapImage GetImagePreview(this MagickImage image, Layer layer, Size size) { using var previewClone = image.Clone(); using var checkerBoard = GetCheckerBoard(layer.Project.size, 45); previewClone.Alpha(AlphaOption.Off); var x = layer.transform.Position.x; var y = layer.transform.Position.y; var isAnchored = layer.transform.IsAnchored; var anchor = layer.transform.Anchor; if (isAnchored) { checkerBoard.Composite(previewClone, anchor, CompositeOperator.SrcOver); } else { checkerBoard.Composite(previewClone, x, y, CompositeOperator.SrcOver); } checkerBoard.Resize(size.width, size.height); var bitmap = checkerBoard.ToBitmapImage(); return(bitmap); }
public ActionResult <FrontendFile> ResizeAllFilters([FromBody] FilterPreviewModel model) { MagickGeometry geometry = model.Geometry; _logger.LogTrace("HTTP request received at preview/resize with geometery of {0}.", geometry); MontageSettings montageSettings = new MontageSettings() { BackgroundColor = MagickColors.None, Geometry = new MagickGeometry(2, 2, 0, 0), TileGeometry = new MagickGeometry(6, 6) }; using (MagickImage magickImage = new MagickImage(model.Image.Data)) { using (MagickImageCollection collection = new MagickImageCollection()) { Parallel.ForEach((IEnumerable <FilterType>) typeof(FilterType).GetEnumValues(), (filter) => { MagickImage magickImageClone = (MagickImage)magickImage.Clone(); magickImageClone.FilterType = filter; magickImageClone.Resize(geometry); collection.Add(magickImageClone); }); using (IMagickImage montage = collection.Montage(montageSettings)) { montage.Format = magickImage.Format; return(new FrontendFile(model.Image.ContentType, montage.ToByteArray())); } } } }
public void Process() { using (var bg = new MagickImage(MagickColor.FromRgba(255, 255, 255, 255), width, height)) { using (var image = new MagickImage(input)) { if (image.HasAlpha == false) { image.Alpha(AlphaOption.Opaque); } using (var cover = image.Clone()) { MagickGeometry resize = new MagickGeometry(width + "x" + height + "^"); image.Resize(resize); image.Extent(width, height, Gravity.Center); image.Blur(80, 30); bg.Composite(image, 0, 0, CompositeOperator.Over); MagickGeometry centerResize = new MagickGeometry(height * 0.7 + "x" + height * 0.7); cover.Resize(centerResize); using (var coverShadow = cover.Clone()) { coverShadow.BackgroundColor = MagickColor.FromRgba(192, 192, 192, 192); coverShadow.Shadow(50, 50, 10, new Percentage(90)); bg.Composite(coverShadow, Gravity.Center, CompositeOperator.Over); } bg.Composite(cover, Gravity.Center, CompositeOperator.Over); } } bg.Write(output); } }
public static MagickImage PerlinNoise(int width, int height) { using var noise1 = new MagickImage(MagickColors.Black, width / 160, height / 160); using var noise2 = new MagickImage(MagickColors.Black, width / 80, height / 80); using var noise3 = new MagickImage(MagickColors.Black, width / 40, height / 40); using var noise4 = new MagickImage(MagickColors.Black, width / 20, height / 20); using var noise5 = new MagickImage(MagickColors.Black, width / 10, height / 10); using var noise6 = new MagickImage(MagickColors.Black, width / 1, height / 1); noise1.AddNoise(NoiseType.Random); noise2.AddNoise(NoiseType.Random); noise3.AddNoise(NoiseType.Random); noise4.AddNoise(NoiseType.Random); noise5.AddNoise(NoiseType.Random); noise1.VirtualPixelMethod = VirtualPixelMethod.Tile; noise2.VirtualPixelMethod = VirtualPixelMethod.Tile; noise3.VirtualPixelMethod = VirtualPixelMethod.Tile; noise4.VirtualPixelMethod = VirtualPixelMethod.Tile; noise5.VirtualPixelMethod = VirtualPixelMethod.Tile; noise6.VirtualPixelMethod = VirtualPixelMethod.Tile; var geometry = new MagickGeometry(width, height) { FillArea = true }; noise1.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.5); noise1.Evaluate(Channels.Default, EvaluateOperator.Add, 0.25); noise1.Resize(geometry); noise2.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.25); noise2.Evaluate(Channels.Default, EvaluateOperator.Add, 0.375); noise2.Resize(geometry); noise3.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.125); noise3.Evaluate(Channels.Default, EvaluateOperator.Add, 0.4375); noise3.Resize(geometry); noise4.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.0625); noise4.Evaluate(Channels.Default, EvaluateOperator.Add, 0.46875); noise4.Resize(geometry); noise5.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.03125); noise5.Evaluate(Channels.Default, EvaluateOperator.Add, 0.484375); noise5.Resize(geometry); noise6.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.015625); noise6.Evaluate(Channels.Default, EvaluateOperator.Add, 0.49921875); noise6.Resize(geometry); noise1.Composite(noise2, CompositeOperator.Plus); noise1.Composite(noise3, CompositeOperator.Plus); noise1.Composite(noise4, CompositeOperator.Plus); noise1.Composite(noise5, CompositeOperator.Plus); noise1.Composite(noise6, CompositeOperator.Plus); noise1.AutoLevel(); return((MagickImage)noise1.Clone()); }
private string Process() { try { using (MagickImage srcMagickImage = new MagickImage(_inputFilePath)) { using (MagickImage grayScaleImage = (MagickImage)srcMagickImage.Clone()) { using (MagickImage beforeImage = new MagickImage(new MagickColor(160, 160, 160, 255), srcMagickImage.Width, srcMagickImage.Height)) { using (MagickImage afterImage = new MagickImage(new MagickColor(56, 56, 56, 255), srcMagickImage.Width, srcMagickImage.Height)) { grayScaleImage.Grayscale(PixelIntensityMethod.Undefined); grayScaleImage.BrightnessContrast(new Percentage(10), new Percentage(10)); grayScaleImage.Composite(beforeImage, CompositeOperator.SoftLight); grayScaleImage.Composite(afterImage, CompositeOperator.Lighten); grayScaleImage.Write(_outputFilePath); return(string.Empty); } } } } } catch (Exception e) { return(e.Message); } }
public void ShouldThrowExceptionWhenNoImageIsRead() { using (var image = new MagickImage()) { Assert.Throws <MagickCorruptImageErrorException>(() => image.Clone()); } }
private bool ProcessSignatureFile(string signatureContent, ref string sigFile, ref string invSigFile) { try { var imageDataByteArray = Convert.FromBase64String(signatureContent); using (var memoryStream = new MemoryStream(imageDataByteArray)) { memoryStream.Position = 0; //await formFileInfo.CopyToAsync(memoryStream); //formFileInfo.CopyTo(memoryStream); using (MagickImage image = new MagickImage(memoryStream.ToArray())) { MagickImage revImg = (MagickImage)image.Clone(); //revImg.Negate(); revImg.Opaque(MagickColors.Black, MagickColors.White); StorageManager manager = new StorageManager(_hostingEnvironment, _configuration); string id = Guid.NewGuid().ToString(); sigFile = manager.UploadMagickImage(image, string.Empty, id + "-org", PikchaConstants.PIKCHA_SIGNATURE_SAVE_EXTENTION, StorageManager.FileCategory.Signature); invSigFile = manager.UploadMagickImage(revImg, string.Empty, id + "-inv", PikchaConstants.PIKCHA_SIGNATURE_SAVE_EXTENTION, StorageManager.FileCategory.Signature); return(true); } } } catch (Exception e) { return(false); } }
/// <summary> /// Processses a scanned document of text to clean the text background and enhance the text. /// </summary> /// <param name="input">The image to execute the script on.</param> public MagickImage Execute(MagickImage input) { if (input == null) { throw new ArgumentNullException("input"); } CheckSettings(); MagickImage output = input.Clone(); RotateImage(output); CropImage(output); ConvertToGrayscale(output); EnhanceImage(output); RemoveNoise(output); UnrotateImage(output); SharpenImage(output); SaturateImage(output); AdaptiveBlurImage(output); TrimImage(output); PadImage(output); return(output); }
private IMagickImage CreatePattern(int width, int height, IMagickImage texture) { var pattern = new MagickImage(MagickColors.None, width, height); pattern.Texture(texture); if (Spread == 0.0) { return(pattern); } if (Spread == 100.0) { pattern.Spread(Spread); return(pattern); } using (IMagickImage mix = pattern.Clone()) { mix.Spread(Spread); pattern.Composite(mix, CompositeOperator.Blend, Mix.ToString(CultureInfo.InvariantCulture)); return(pattern); } }
public void Execute(PipelineContext context, MagickImage magickImage) { foreach (MagickGeometry dimensions in Config.Geometries) { using (MagickImage dimensionsMagickImage = (MagickImage)magickImage.Clone()) { PipelineContext contextClone = context.Clone(); contextClone.AppendPath(dimensions.ToString()); if (dimensions.Width < 0 || dimensions.Height < 0) { Logger.Fatal("The height and width of dimensions can not be negative."); } if (dimensions.Width == 0 && dimensions.Height == 0) { Logger.Fatal("Both height and width in the dimensions configuration were 0, please specify at least one."); } dimensionsMagickImage.FilterType = Config.Filter; dimensionsMagickImage.Resize(dimensions); contextClone.Next(dimensionsMagickImage); } } }
/// <summary> /// Save the image considering crop /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuSaveClick(object sender, RoutedEventArgs e) { var imageToSave = magickImage.Clone(); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = GetFileDialogFilter(); // Crop with the good ratio double xRatio = imageToSave.Width / imgCanvas.ActualWidth; double yRatio = imageToSave.Height / imgCanvas.ActualHeight; MagickGeometry geometry = new MagickGeometry(); geometry.Width = (int)(cropTool.ActualWidth * xRatio); geometry.Height = (int)(cropTool.ActualHeight * yRatio); geometry.X = (int)(Canvas.GetLeft(cropTool) * xRatio); geometry.Y = (int)(Canvas.GetTop(cropTool) * yRatio); imageToSave.Crop(geometry); if (saveFileDialog.ShowDialog() == true) { if (File.Exists(saveFileDialog.FileName)) { File.Delete(saveFileDialog.FileName); } using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create)) { imageToSave.Write(fs); } } }
public bool OverrideTextureMaps(string textureName, double reflection, double gloss, double specular) { if (Kn5 == null) { return(false); } if (_mapsBase == null) { Format format; var data = TextureReader.ToPng(DeviceContextHolder, Kn5.TexturesData[textureName], true, out format); _mapsBase = new MagickImage(data); if (_mapsBase.Width > 256 || _mapsBase.Height > 256) { _mapsBase.Resize(256, 256); } _mapsBase.AutoLevel(Channels.Red); _mapsBase.AutoLevel(Channels.Green); _mapsBase.AutoLevel(Channels.Blue); } using (var image = _mapsBase.Clone()) { image.Evaluate(Channels.Red, EvaluateOperator.Multiply, specular); image.Evaluate(Channels.Green, EvaluateOperator.Multiply, gloss); image.Evaluate(Channels.Blue, EvaluateOperator.Multiply, reflection); return(OverrideTexture(textureName, image.ToByteArray(MagickFormat.Png))); } }
private void ApplyWhiteBalance(MagickImage image) { using (var mask = image.Clone()) { mask.ColorSpace = ColorSpace.HSB; mask.Negate(Channels.Green); using (var newMask = mask.Separate(Channels.Green).First()) { using (var maskBlue = mask.Separate(Channels.Blue).First()) { newMask.Composite(maskBlue, CompositeOperator.Multiply); } newMask.ContrastStretch((Percentage)0, WhiteBalance); newMask.InverseOpaque(new MagickColor("white"), new MagickColor("black")); double maskMean = GetMean(newMask); double redRatio = GetRatio(image, Channels.Red, newMask, maskMean); double greenRatio = GetRatio(image, Channels.Green, newMask, maskMean); double blueRatio = GetRatio(image, Channels.Blue, newMask, maskMean); var matrix = new MagickColorMatrix(3, redRatio, 0, 0, 0, greenRatio, 0, 0, 0, blueRatio); image.ColorMatrix(matrix); } } }
public void Execute(PipelineContext context, MagickImage magickImage) { ResolvedData maskFileInfo = context.DataResolver.ResolvedData("masks", context.ResolvedData, Config.Mask.Pattern); if (Config.Original) { PipelineContext contextClone = context.Clone(); contextClone.AppendPath(OriginalDirectory); contextClone.Next(magickImage); } if (maskFileInfo != null) { using (MagickImage maskMagickImage = maskFileInfo.ToMagickImage()) { magickImage.SetWriteMask(maskMagickImage); } } foreach (Modulation modulate in Config.Modulation) { using (MagickImage modulatedMagickImage = (MagickImage)magickImage.Clone()) { PipelineContext contextClone = context.Clone(); contextClone.AppendPath($"{modulate.Name}"); contextClone.AppendPrefix(modulate.Prefix ?? modulate.Name.Substring(0, 1)); modulatedMagickImage.Modulate(modulate.Brightness, modulate.Saturation, modulate.Hue); modulatedMagickImage.RemoveWriteMask(); contextClone.Next(modulatedMagickImage); } } }
public static void NeonSign() { using (var images = new MagickImage()) { var backgroundImage = new MagickImage(new MagickColor(System.Drawing.Color.Black), 400, 175); var text = new MagickImage(); text.Settings.BackgroundColor = new MagickColor(); text.BorderColor = new MagickColor(System.Drawing.Color.Black); text.Settings.FillColor = System.Drawing.Color.DodgerBlue; text.Settings.FontPointsize = 72; text.Read("label:I M EXamples"); var clone = text.Clone(); clone.Blur(0, 25); clone.Level((Percentage)5, (Percentage)75); text.Composite(clone, CompositeOperator.Overlay); backgroundImage.Composite(text, CompositeOperator.Over); // backgroundImage.Composite(clone, CompositeOperator.Over); backgroundImage.Write("cloned.png"); }; }
public static MagickImage PadImage(MagickImage image, int x, int y) { MagickImage result = (MagickImage)image.Clone(); int[] newDimensions = Helper.GetGoodDimensions(image.Width, image.Height, x, y); result.Extent(newDimensions[0], newDimensions[1]); return(result); }
private static MagickImage SelectiveBlur(MagickImage image) { MagickImage result = image.Clone(); result.SelectiveBlur(0, 5, new Percentage(10)); return(result); }
public static MagickImage ResizeAndFill(MagickImage img, MagickGeometry size, MagickColor fill) { MagickImage i = (MagickImage)img.Clone(); i.Resize(size); i.Extent(size, Gravity.Center, fill); return(i); }
private static MagickImage ExtractAlpha(MagickImage image, MagickColor color) { var alpha = image.Clone(); alpha.InverseTransparent(color); alpha.Alpha(AlphaOption.Extract); return(alpha); }
/// <summary> /// Transforms an image to place it in a region of a tshirt image. The transformed image will /// display hightlights from the tshirt image and be distorted to match the wrinkles in the /// tshirt image. /// </summary> /// <param name="tshirt">The image of the shirt to put the overlay on.</param> /// <param name="overlay">The overlay to put on top of the shirt.</param> /// <returns>The resulting image.</returns> public MagickImage Execute(MagickImage tshirt, MagickImage overlay) { if (tshirt == null) { throw new ArgumentNullException("tshirt"); } if (overlay == null) { throw new ArgumentNullException("overlay"); } CheckSettings(tshirt); var x = _coords[1].X - _coords[0].X; var y = _coords[1].Y - _coords[0].Y; var topWidth = Math.Sqrt((x * x) + (y * y)); var scale = (overlay.Width - 1) / (topWidth / 1); var overlayCoordinates = CreateOverlayCoordinates(overlay, scale); var tshirtCoordinates = CreateTshirtCoordinates(overlay, scale, topWidth); var alpha = ExtractAlpha(tshirt); var gray = ToGrayScale(tshirt); var mean = SubtractMean(gray, tshirtCoordinates); ApplyLighting(mean); var light = mean.Clone(); mean.Dispose(); var blur = gray.Clone(); ApplyBlur(blur); var distorted = DistortOverlay(gray, overlay, overlayCoordinates, tshirtCoordinates); var displaced = DisplaceOverlay(distorted, light, blur); distorted.Dispose(); light.Dispose(); blur.Dispose(); var output = tshirt.Clone(); output.Composite(displaced, CompositeOperator.Over); displaced.Dispose(); if (alpha != null) { output.Alpha(AlphaOption.Off); output.Composite(alpha, CompositeOperator.CopyAlpha); alpha.Dispose(); } return(output); }
static MagickImage getAlphaMask3(MagickImage origin, string color = "white") { // convert bg_finer.png -transparent white -alpha extract bg_finer_not.png var clone = (MagickImage)origin.Clone(); clone.Transparent(new MagickColor(color)); clone.Alpha(AlphaOption.Extract); return(clone); }
private static MagickImage ToGrayScale(MagickImage image) { var gray = image.Clone(); gray.Alpha(AlphaOption.Off); gray.ColorSpace = ColorSpace.Gray; return(gray); }
public void ShouldCloneTheImage() { using (var image = new MagickImage(Files.Builtin.Logo)) { var clone = image.Clone(); Assert.False(ReferenceEquals(image, clone)); } }
/// <summary> /// Checks if normal map is already converted to PS3 format. /// </summary> /// <param name="dds">A DXT1/DXT3/DXT5/A8R8G8B8 DDS format normal map MagickImage.</param> /// <returns>True or false if the normal map has been converted to PS3 already.</returns> private static bool IsConvertedToPS3(this MagickImage dds) { List <IMagickImage <ushort> > clonedChannelsList = new MagickImage(dds.Clone()).Separate().ToList(); clonedChannelsList[1].MakeNull(); // Makes green channel null for upcoming comparison, because green channel is untouched int nullCheckIndex = dds.HasAlpha ? 2 : 0; return(clonedChannelsList[nullCheckIndex].Equals(clonedChannelsList[1])); }
static MagickImage getResult6(MagickImage patternedBackground, MagickImage content) { /* * convert -composite bg_mask_pattern-1.png content.png final.png */ var clone = content.Clone(); clone.Composite(patternedBackground, CompositeOperator.Darken); return((MagickImage)clone); }
public void Test_Clone() { MagickImage first = new MagickImage(Files.SnakewarePNG); MagickImage second = first.Clone(); Test_Clone(first, second); second = new MagickImage(first); Test_Clone(first, second); }