Gradient direction

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
Bert
Posts: 12
Joined: 2018-06-29T05:04:42-07:00
Authentication code: 1152

Gradient direction

Post 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?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Gradient direction

Post 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");
}
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Bert
Posts: 12
Joined: 2018-06-29T05:04:42-07:00
Authentication code: 1152

Re: Gradient direction

Post by Bert »

That did the trick. Thank you very much!
Post Reply