Page 1 of 1

Gradient direction

Posted: 2018-07-03T03:31:12-07:00
by Bert
See following ImageMagick command (taken from https://www.imagemagick.org/script/gradient.php)

Code: Select all

magick -size 256x128 -define gradient:direction=east gradient:black-white linear_gradient_east.png
I've managed to translate it to .NET, except the gradient:direction part

I've tried various things as seen in the code, but none of them do what I expect it to do.

Code: Select all

var complete = new MagickImage(MagickColors.Transparent, 100, 100);

using (var fill = new MagickImage(MagickColors.Blue, 50, 100))
using (var gradient = new MagickImage($"gradient:blue-none", 50, 100))
{
    // Rotates the entire image, not the rotation of the gradient
    //gradientMask.Rotate(90);
    // Does nothing
    //gradient.Settings.SetDefine("gradient:direction", "east");
    //gradient.Settings.SetDefine("gradient:direction", "East");
    //gradient.Settings.SetDefine("direction", "east");
    //gradient.Settings.SetDefine("direction", "East");

    complete.Composite(fill, 0, 0, CompositeOperator.Over);
    complete.Composite(gradient, 50, 0, CompositeOperator.Over);
}

// Save image etc.

complete.Dispose();
So my question is, how do I translate

Code: Select all

-define gradient:direction=east
to Magick.NET?

Re: Gradient direction

Posted: 2018-07-03T11:30:29-07:00
by dlemstra
The command would translate to this:

Code: Select all

var readSettings = new MagickReadSettings()
{
    Width = 256,
    Height = 128
};

readSettings.SetDefine("gradient:direction", "east");

using (var image = new MagickImage("gradient:black-white", readSettings))
{
    image.Write("linear_gradient_east.png");
}

Re: Gradient direction

Posted: 2018-07-03T21:53:00-07:00
by Bert
That did the trick. Thank you very much!