Creating image with label text

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
dbibby
Posts: 2
Joined: 2018-05-07T08:04:44-07:00
Authentication code: 1152

Creating image with label text

Post by dbibby »

Is there some sample c# code that uses Magich.Net to create an image using the label option (I want to put text on the image) so I can take advantage the sizing options?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Creating image with label text

Post by dlemstra »

Do you have a command line example of what you want to do? If you want to create a labels you can just do: new MagickImage("label:Your Text"). And if you want to control the font and the font size you can use the overload that accepts readsettings.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
dbibby
Posts: 2
Joined: 2018-05-07T08:04:44-07:00
Authentication code: 1152

Re: Creating image with label text

Post by dbibby »

Hey,

Thanks for responding. I searched around some more and was able to find an example that helped me out:

Code: Select all

using (MagickImage image = new MagickImage())
{
  MagickReadSettings settings = new MagickReadSettings()
  {
    BackgroundColor = MagickColors.LightBlue, // -background lightblue
    FillColor = MagickColors.Black, // -fill black
    Font = "Arial", // -font Arial 
    Width = 530, // -size 530x
    Height = 175 // -size x175
  };

  image.Read("caption:This is a test.", settings); // caption:"This is a test."
  image.Write("caption_long_en.png"); // caption_long_en.png
}
I am using label instead of caption and I am only setting the width
As I understand it the label text and the height will scale when the width is changed.
My task it to create an image with text on the fly, and the users input the width and have the image and text scale with the width change.
So, looks like it's working.
Post Reply