public VectorFont(string systemFont) { m_family = SystemFonts.Families.Where(family => family.Name == systemFont).SingleOrDefault() ?? throw new ArgumentException(nameof(systemFont)); m_font = m_family.CreateFont(64, FontStyle.Regular); AddCharacters("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,<.>/?;:'\"\\|]}[{`~_-=+!@#$%^&^*()"); }
public VectorFont(Stream fontStream) { m_family = m_collection.Install(fontStream); m_font = m_family.CreateFont(64, FontStyle.Regular); AddCharacters("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,<.>/?;:'\"\\|]}[{`~_-=+!@#$%^&^*()"); }
static void Main(string[] args) { System.IO.Directory.CreateDirectory("output"); using (Image <Rgba32> img = new Image <Rgba32>(1500, 500)) { PathBuilder pathBuilder = new PathBuilder(); pathBuilder.SetOrigin(new PointF(500, 0)); pathBuilder.AddBezier(new PointF(50, 450), new PointF(200, 50), new PointF(300, 50), new PointF(450, 450)); // add more complex paths and shapes here. IPath path = pathBuilder.Build(); SixLabors.Fonts.FontCollection fontCollection = new FontCollection(); SixLabors.Fonts.Font carlitoFont = fontCollection.Install(Directory.GetCurrentDirectory() + "/font/Carlito-Regular.ttf") .CreateFont(14, FontStyle.Regular); string text = "Hello World Hello World Hello World Hello World Hello World"; var textGraphicsOptions = new TextGraphicsOptions(true) // draw the text along the path wrapping at the end of the line { WrapTextWidth = path.Length }; var point = new PointF(100, 100); img.Mutate(ctx => ctx .Fill(Rgba32.White) // white background image .Draw(Rgba32.Gray, 3, path) // draw the path so we can see what the text is supposed to be following .DrawText(textGraphicsOptions, text, carlitoFont, Rgba32.Black, point)); img.Save("output/path.png"); } }
public static System.IO.Stream WriteTextToImage(string text) { using (SixLabors.ImageSharp.Image image = SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32> .Load("Assets/share-bg.png")) { SixLabors.Fonts.FontCollection fontCollection = new SixLabors.Fonts.FontCollection(); SixLabors.Fonts.Font regularFont = fontCollection.Install("Assets/TitilliumWeb-SemiBold.ttf").CreateFont(24, SixLabors.Fonts.FontStyle.Regular); SixLabors.Fonts.Font italicFont = fontCollection.Install("Assets/TitilliumWeb-BoldItalic.ttf").CreateFont(24, SixLabors.Fonts.FontStyle.Italic); image.Mutate(x => x.DrawText(text, regularFont, SixLabors.ImageSharp.Color.White, new SixLabors.ImageSharp.PointF(100, 100))); System.IO.MemoryStream stream = new System.IO.MemoryStream(); image.Save(stream, new SixLabors.ImageSharp.Formats.Png.PngEncoder()); stream.Position = 0; return(stream); } }
static void Main(string[] args) { System.IO.Directory.CreateDirectory("output"); using (var img = Image.Load("fb.jpg")) { SixLabors.Fonts.FontCollection fontCollection = new FontCollection(); SixLabors.Fonts.Font carlitoFont = fontCollection.Install(Directory.GetCurrentDirectory() + "/font/Carlito-Regular.ttf") .CreateFont(14, FontStyle.Regular); using (var img2 = img.Clone(ctx => ctx.ApplyScalingWaterMark(carlitoFont, longText, Rgba32.HotPink, 5, true))) { img2.Save("output/watermarked.png"); } // the original `img` object has not been altered at all. } }