Viuツ
Viuツ

Reputation: 99

C# ImageMagick using custom Fonts

I was trying to change the font in my IMagick project. I wanted to use a custom fonts, but apparently it does not work!

Here is my code:

            PrivateFontCollection modernFont = new PrivateFontCollection();

            modernFont.AddFontFile(path);

                var readSettings = new MagickReadSettings()
                {

                    FontFamily = "Walrus Bold",
                    FontPointsize = 130,
                    TextGravity = Gravity.Center,
                    StrokeColor = MagickColors.White,
                    StrokeWidth = 4,
                    BackgroundColor = MagickColors.Transparent,
                    Height = 150,
                    Width = 600 
                };
                using (var image = new MagickImage(path))
                {
                    using (var caption = new MagickImage($"caption:{idolname}", readSettings))
                    {
                        
                        image.Composite(caption, textWidth + 90, textHeight + 155, CompositeOperator.Over);

                        image.Write(path);
                    }
                }

I already printed the name of the font and it's like that in the modernfont.Families method. I tried to use the font in something else and it worked there.

Anyone an idea how I can implement it?

Upvotes: 0

Views: 958

Answers (1)

dlemstra
dlemstra

Reputation: 8153

You can also specify the full path to the font instead of the font name:

var readSettings = new MagickReadSettings()
{
    Font = path
}

Upvotes: 3

Related Questions