I have a string array where each element should be a line in my output image. For example
Sample output: (with a background and centered)
Hello
World
I'm doing something like: (
Thanks in advance
string[] input= new string[2] {"Hello", "World"};
I need to iterate on this array and create an output image (gif) where each letter uses a custom image (see the code below), I would like to have an output image with a background where my "text" is centered (vertically and horizontally)Sample output: (with a background and centered)
Hello
World
I'm doing something like: (
foreach (var line in input) // input is the array where I have the text
{
foreach (var letter in line)
{
// Depending on the letter load the specific image
MagickImage image = new MagickImage($"{InputPath}\\{letter}.png");
// TODO: Allow multiple lines, the following resize and extend are just some of the tests
// image.Resize(960, 540);
// image.Extent(960, 540, Gravity.Center);
// image.Extent(-5, -80 * position, 80, 540);
// When I have just one line it works very nice, just doing this:
image.BackgroundColor = MagickColors.Transparent;
collection.Add(image);
}
position++; // this is the current line
}
// Then I'm appending my collection horizontally and adding the background image:
using (MagickImage horizontal = collection.AppendHorizontally())
{
horizontal.Extent(new MagickGeometry(960, 540), Gravity.Center);
using (MagickImage background = new MagickImage("background.png"))
{
horizontal.Composite(background, CompositeOperator.DstAtop);
horizontal.Write($"{OutputPath}\\test.png");
}
}
Can anyone please help me with this issue appending multiple rows?Thanks in advance