public void ShouldUseTheSpecifiedDensity() { var image = new MagickImage(MagickColors.Purple, 500, 500); var pointSize = new DrawableFontPointSize(20); var text = new DrawableText(250, 250, "Magick.NET"); image.Draw(pointSize, new DrawableDensity(96), text); image.Trim(); Assert.Equal(144, image.Width); Assert.Equal(24, image.Height); }
public void ShouldUseTheDefaultDensity() { using (var image = new MagickImage(MagickColors.Purple, 500, 500)) { var pointSize = new DrawableFontPointSize(20); var text = new DrawableText(250, 250, "Magick.NET"); image.Draw(pointSize, text); image.Trim(); Assert.Equal(108, image.Width); Assert.Equal(19, image.Height); } }
private IMagickImage CreateImage(int?density) { IMagickImage image = new MagickImage(MagickColors.Purple, 500, 500); DrawableFontPointSize pointSize = new DrawableFontPointSize(20); DrawableText text = new DrawableText(250, 250, "Magick.NET"); if (!density.HasValue) { image.Draw(pointSize, text); } else { image.Draw(pointSize, new DrawableDensity(density.Value), text); } image.Trim(); return(image); }
public static string AddTextToImage(string imageFile, string text) { var image = new MagickImage(imageFile); using (var imgText = new MagickImage()) { var drawable = new DrawableText(0, 10, text); var gravity = new DrawableGravity(Gravity.North); var font = new DrawableFont("Arial"); var antialias = new DrawableTextAntialias(true); var size = new DrawableFontPointSize(50); var color = new DrawableFillColor(Color.Snow); var strokeColor = new DrawableStrokeColor(Color.OrangeRed); image.Draw(drawable, gravity, font, antialias, size, color, strokeColor); } // Save the result string outputImage = TempFolder + "\\waterMark_" + Path.GetFileName(imageFile); image.Write(outputImage); return(outputImage); }
public void Stamp(ThumbnailSheetCreateRequest request, string filePath, TimeSpan time) { var stampText = time.ToString(request.VideoDurationInSeconds >= 3600 ? @"hh\:mm\:ss" : @"mm\:ss"); var tempFilePath = filePath + ".tmp.png"; using (var imgText = new MagickImage(filePath)) { var drawable = new DrawableText(5, 5, stampText); var gravity = new DrawableGravity(Gravity.Southeast); var font = new DrawableFont("Tahoma"); var antialias = new DrawableTextAntialias(true); var size = new DrawableFontPointSize(48); var color = new DrawableFillColor(MagickColors.Black); var strokecolor = new DrawableStrokeColor(MagickColors.AliceBlue); imgText.Draw(drawable, gravity, font, antialias, size, color, strokecolor); imgText.Write(tempFilePath); } File.Delete(filePath); File.Move(tempFilePath, filePath); }
static public IDrawables <byte> FontPointSize( this IDrawables <byte> drawable, DrawableFontPointSize fontPointSize) => drawable.FontPointSize(fontPointSize.PointSize);