This project has moved and is read-only. For the latest updates, please go here.

Annotating Images - Labeling Below (or Above) an Image

May 15, 2015 at 7:05 AM
Greetings,

First, I would like to thank MagickImage team for the amazing effort and the great functionality this environment is providing.

I am new to the MagickImage, Magick.NET specifically. I am interested to start by appending some text to the image as a footer. I don't want the text to overlay the image, but I want the text to be appended to the bottom as an extra portion. I tried to search on how to do that in .NET, but unfortunately I could not find the way. I saw how to so using the command line, but I need some help in doing the same in .NET environment. The command line that I saw is as follows:

convert dragon.gif -background Khaki label:'Faerie Dragon' \
      -gravity Center -append    anno_label.jpg
Source: http://www.imagemagick.org/Usage/annotating/


I am asking for your help in applying the same in .NET code.

I appreciate your help.

Thanks,
Menhal
May 15, 2015 at 1:32 PM
You can either use the Annotate method of MagickImage or 'read' the label and append it to your image. Below are two examples of how you could do this:
// Fixed label height
using (MagickImage image = new MagickImage("logo:"))
{
  image.Extent(image.Width, image.Height + 20, Gravity.North, new MagickColor("Plum"));
  image.Annotate("Magick.NET", Gravity.South);
  image.Write("output-a.png");
}

// Dynamic label height
using (MagickImageCollection images = new MagickImageCollection())
{
  // Read the image you want to put a label on.
  MagickImage logo = new MagickImage("logo:");
  images.Add(logo);

  MagickImage label = new MagickImage();
  label.BackgroundColor = new MagickColor("Khaki");
  label.Read("label:Magick.NET");
  // Resize the label to the width of the image and place the text in the center
  label.Extent(logo.Width, label.Height, Gravity.Center);
  images.Add(label);

  // Append the images
  using (MagickImage output = images.AppendVertically())
  {
    output.Write("output-b.png");
  }
}
May 17, 2015 at 5:53 AM
Thank you very much for your answer. I have used the second approach and it does what I exactly need.