Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: Issue with custom fonts

$
0
0
Hi All,

Currently I'm writting a tool which will generate font images based on user choice. Currently everything works apart from using custom fonts. Currently it always seems to go to a default, but I need it to be able to use ".ttf" files.

This is my current implementation.
private void OutputFont(Char output)
        {
            MagickImage fontTest = new MagickImage(Color.Transparent, Int32.Parse(Width_Text_Box.Text), Int32.Parse(Height_Text_Box.Text))
            {
                Format = MagickFormat.Png
            };
            // Font parameters
            DrawableFont font = new DrawableFont("Fonts/28_Days_Later.ttf");
            DrawableFontPointSize pointSize = new DrawableFontPointSize(Int32.Parse(FontSize_TxtBox.Text));
            DrawableFillColor fillColor = new DrawableFillColor(_FillColour);
            // Outline
            DrawableStrokeColor strokeColor = new DrawableStrokeColor(_OutlineColour);
            DrawableStrokeWidth strokeWidth = new DrawableStrokeWidth(1);
            // Antialiasing
            DrawableStrokeAntialias strokeAntialias = new DrawableStrokeAntialias(true);
            DrawableTextAntialias textAntialias = new DrawableTextAntialias(true);
            // Text output
            DrawableText text = new DrawableText(0, 0, $"{output}");
            DrawableGravity gravity = new DrawableGravity(Gravity.Center);
            // Settings
            IDrawable[] parameters = new IDrawable[] { font, pointSize, fillColor, strokeColor, strokeWidth, strokeAntialias, textAntialias, text, gravity };

            fontTest.Draw(parameters);
            String upper = Char.IsUpper(output) ? "u" : "";
            fontTest.Write($"Output/{output}{upper}.png");
        }
Does anyone have any experience with doing something like this?

Thanks in advance,

Elliott

Viewing all articles
Browse latest Browse all 3693

Trending Articles