Reputation: 131
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?
Upvotes: 3
Views: 4036
Reputation: 8163
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
}
Upvotes: 3