3

I am trying to generate an image file of a caption for scaling. Using the command prompt I have been able to achieve this goal:

convert -background lightblue -fill black -font Arial -size 530x175  caption:"This is a test." caption_long_en.png

I am now trying to do the same using Magick.NET

class ImageResizer
{
    public Image ResizeImage()
    {
        MagickImage image = new MagickImage();
        image.BackgroundColor = new MagickColor(Color.lightblue);
        .....
    }

But am admittedly having some trouble: After initializing my image I don't see options to define the fill, font, size and caption that I wish to use to generate my image.

Could anybody point me in the right direction for how to accomplish the command line above using Magick.NET?

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
markdozer
  • 121
  • 3
  • 8
  • Define "some trouble" please. – Quality Catalyst May 17 '16 at 19:56
  • @QualityCatalyst..sorry should have been more specific. After initializing my image I don't see options to define the fill, font, size and caption that I wish to use to generate my image. I was trying to gain some more understanding on how to define those options using Magick.NET – markdozer May 17 '16 at 20:00

1 Answers1

3

The options that are specified before the image is read (caption:"This is a test") need to be specified with the MagickReadSettings class. Below is an example of how you can use that class:

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
}
dlemstra
  • 7,813
  • 2
  • 27
  • 43
  • is there a way to account for right to left language conversion in the caption (i.e. if my string is in Arabic)? – markdozer May 19 '16 at 16:37