Page 1 of 1

Creating image with label text

Posted: 2018-05-07T08:13:52-07:00
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?

Re: Creating image with label text

Posted: 2018-05-07T10:28:20-07:00
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.

Re: Creating image with label text

Posted: 2018-05-08T05:29:30-07:00
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.