Page 1 of 1

Gradient options via MagickWand

Posted: 2019-02-19T10:11:18-07:00
by IMUser
The following is a similar post, but it was posted 12 years ago, so I'm posting this.

viewtopic.php?f=6&t=8149&p=24951&hilit= ... ent#p24951


I have installed the most recent version of ImageMagick (7.0.8-27 Q16 x64 2019-02-09) on a Windows 7 computer.

I would like to know if the gradient options can be used in MagickWand—the options that are listed on https://imagemagick.org/script/gradient.php, that can be set using the -define argument in command line.

I know that the following MagickWand code generates a gradient.

Code: Select all

MagickReadImage(magick_wand,"gradient:black-white");
However, I've tried the following and it doesn't work.

Code: Select all

MagickReadImage(magick_wand,"gradient:black-white -define gradient:direction=East");
The above code seems to ignore "-define gradient:direction=East" entirely, and it creates the gradient without applying the -define argument.

The following code generates an error.

Code: Select all

MagickReadImage(magick_wand,"-define gradient:direction=East gradient:black-white");
Magick exception description: unable to open image '-define gradient:direction=East gradient:black-white': Invalid argument @ error/blob.c/OpenBlob/3485
Magick exception severity: 435
Magick exception type: 435

Is it possible to use the gradient options via MagickWand? If so, how?

Re: Gradient options via MagickWand

Posted: 2019-02-19T21:51:48-07:00
by snibgo
The define affects the image creation, so needs to occur before the image is created. The usual MagickWand functions for define work with an image, so can only occur after the image is created.

The CLI "-define" works on an image_info structure, so can be used before an image is created.

MagickWand doesn't support API access to an image_info.

A workaround is to #include magick-wand-private.h, so we use can use MagickCore functions that operate on the wand's image_info, eg:

Code: Select all

if (!SetImageOption(magick_wand->image_info, "gradient:direction", "East")) {
  ThrowWandException(magick_wand);
}
if (!MagickReadImage(magick_wand, "gradient:black-white")) {
  ThrowWandException(magick_wand);
}
That's the only method I know, but perhaps there is a better way.

Re: Gradient options via MagickWand

Posted: 2019-04-12T12:26:39-07:00
by emcconville
The `MagickSetOption` method is what you'll need to call before `MagickReadImage`.

Code: Select all

MagickSetOption(magick_wand, "gradient:direction", "East");
MagickReadImage(magick_wand, "gradient:black-white");

Re: Gradient options via MagickWand

Posted: 2019-04-12T14:38:48-07:00
by snibgo
Thanks, emcconville.