How do I use Magick++ API to create a radial gradient?
-
- Posts: 11
- Joined: 2015-04-13T14:53:20-07:00
- Authentication code: 6789
How do I use Magick++ API to create a radial gradient?
Hey, guys!
I've been looking for any image gradients methods in the Magick++ API but I can't find anything. I need to add a radial gradient to an image. Although I found ImageGradient method in MagickCore API, but I haven't seen into it yet. Is there any method in Magick++ API that does what I want or I should use that one from MagickCore API?
Thank you for all your support!
P.S. API version is Magick++ 6.9.1.1. Q16.
I've been looking for any image gradients methods in the Magick++ API but I can't find anything. I need to add a radial gradient to an image. Although I found ImageGradient method in MagickCore API, but I haven't seen into it yet. Is there any method in Magick++ API that does what I want or I should use that one from MagickCore API?
Thank you for all your support!
P.S. API version is Magick++ 6.9.1.1. Q16.
Re: How do I use Magick++ API to create a radial gradient?
Would you mind posting the command line commands that you are trying to reproduce in the Magick++ API?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How do I use Magick++ API to create a radial gradient?
In command line, one creates a radial gradient using:
See pseudo image formats at http://www.imagemagick.org/script/formats.php#pseudo
Code: Select all
convert -size WxH radial-gradient: resultimage
-
- Posts: 11
- Joined: 2015-04-13T14:53:20-07:00
- Authentication code: 6789
Re: How do I use Magick++ API to create a radial gradient?
I have tried to reproduce this:
Here is a code I wrote that reproduces it:
It works but I haven't tested it properly so there is a work to do. Any suggestions and/or admonishments are welcomed. Thank you guys for your help!
Code: Select all
convert -size WxH radial-gradient:inner-outer result
Code: Select all
void retrieveColor(Magick::PixelPacket& to, const Magick::Color& from)
{
to.blue = from.blueQuantum();
to.green = from.greenQuantum();
to.red = from.redQuantum();
to.opacity = from.alphaQuantum();
}
void radialGradient( Magick::Image& image,
const Magick::Color innerColor,
const Magick::Color outerColor )
{
Magick::PixelPacket startColor, stopColor;
retrieveColor(startColor, innerColor);
retrieveColor(stopColor, outerColor);
image.modifyImage();
MagickCore::GradientImage( image.image(),
MagickCore::RadialGradient,
MagickCore::PadSpread,
&startColor,
&stopColor );
}
Re: How do I use Magick++ API to create a radial gradient?
'radial-gradient:inner-outer' is the name of the 'file' on the command line. So you can just do something like this:
edit: Updated my example after Fred his comment.
Code: Select all
size_t W=100;
size_t H=100;
Magick::Image img;
img.size(Geometry(W, H));
img.read("radial-gradient:purple-yellow");
img.write("result.png");
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How do I use Magick++ API to create a radial gradient?
inner-outer is optional and represents the desired colors which default to black and white
-
- Posts: 11
- Joined: 2015-04-13T14:53:20-07:00
- Authentication code: 6789
Re: How do I use Magick++ API to create a radial gradient?
Could you please explain what it is? You read radial-gradient:purple-yellow file and then save it as a result.png. But what is a radial-gradient:purple-yellow file? How did you get it?dlemstra wrote:'radial-gradient:inner-outer' is the name of the 'file' on the command line. So you can just do something like this:
edit: Updated my example after Fred his comment.Code: Select all
size_t W=100; size_t H=100; Magick::Image img; img.size(Geometry(W, H)); img.read("radial-gradient:purple-yellow"); img.write("result.png");
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How do I use Magick++ API to create a radial gradient?
radial-gradient: is an internal IM pseudo-image that IM creates on the fly with the colors specified. See http://www.imagemagick.org/script/formats.php#pseudo
-
- Posts: 11
- Joined: 2015-04-13T14:53:20-07:00
- Authentication code: 6789
Re: How do I use Magick++ API to create a radial gradient?
That's cool! I got it. Thus I don't have to use MagickCore API for that. Thank you so much!