Gradient options via MagickWand

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
IMUser
Posts: 8
Joined: 2011-06-14T21:05:02-07:00
Authentication code: 8675308

Gradient options via MagickWand

Post by IMUser » 2019-02-19T10:11:18-07:00

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?

snibgo
Posts: 11820
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Gradient options via MagickWand

Post by snibgo » 2019-02-19T21:51:48-07:00

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.
snibgo's IM pages: im.snibgo.com

emcconville
Posts: 2
Joined: 2016-03-11T13:06:45-07:00
Authentication code: 1151
Contact:

Re: Gradient options via MagickWand

Post by emcconville » 2019-04-12T12:26:39-07:00

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");

snibgo
Posts: 11820
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Gradient options via MagickWand

Post by snibgo » 2019-04-12T14:38:48-07:00

Thanks, emcconville.
snibgo's IM pages: im.snibgo.com

Post Reply