I'm trying to create the following:
Text (in any color) on a transparent background which in itself starts fading into nothing (transparency) starting from a certain width.
This is an example that I've made in Photoshop (using a Layer Mask) and what it should be:
This is the code I'm using at the moment (might be a bit convoluted, I used it mainly to test things out)
Code: Select all
using System.Drawing;
using ImageMagick;
namespace TextToPicture
{
class Slideshow
{
static void Main(string[] args)
{
using (var completeMaskText = new MagickImage(MagickColors.Transparent, 310, 30))
{
var gradientSettings = new MagickReadSettings()
{
Width = 270,
Height = 30
};
gradientSettings.SetDefine("gradient:direction", "east");
Color r = Color.FromArgb(255, 0, 0);
using (var filledMaskText = new MagickImage(MagickColors.White, 40, 30))
using (var gradientMaskText = new MagickImage($"gradient:white-none", gradientSettings))
{
completeMaskText.Composite(filledMaskText, 0, 0, CompositeOperator.Over);
completeMaskText.Composite(gradientMaskText, 40, 0, CompositeOperator.Over);
}
using (var mText = new MagickImage(MagickColors.Transparent, 310, 30))
{
var textSettings = new MagickReadSettings
{
BackgroundColor = MagickColors.Transparent,
FillColor = r,
Width = 310,
Height = 30,
};
mText.Read($"label:Hello World hello world hello world!", textSettings);
using (var completeTextBox = new MagickImage(MagickColors.Transparent, 310, 30))
{
using (var text = new MagickImage(MagickColors.Transparent, 310, 30))
{
text.Density = new Density(300);
text.Format = MagickFormat.Png;
text.Composite(mText, 0, 0, CompositeOperator.Over);
text.Composite(completeMaskText, 0, 0, CompositeOperator.Multiply);
text.Write(@"D:\result.png");
}
}
}
}
}
}
}
So I thought: I'll change the gradient from red to transparent instead, which makes the red darker (which is logical, because it puts red on red, but this is also not what I want).
Then I tried creating an actual Layer Mask (like I've done in Photoshop) but if I use CopyAlpha the Alpha channel has to be turned off, which removes the initial transparency...
I'm kind of lost at the moment, if you guys can help me out with this I'd be grateful.