Page 1 of 1

drawing with gradients

Posted: 2010-09-09T05:27:06-07:00
by mizerydearia
I would like to draw a circle and to have it filled with a gradient as well as possible having the border/thickness of the circle to have a gradient as well.

I examined http://www.imagemagick.org/Usage/draw/ as well as several other pages but was unable to find any reference to drawing a shape and to have it filled with a gradient.

I am writing a php script to generate an image based on user input. This is what I wrote so far:

Code: Select all

<?
	foreach(${"_" . $_SERVER["REQUEST_METHOD"]} as $k=>$v) $$k=$v;

	// Create image
		$w = 240; $h = 240;
		$im = new Imagick();
		$im->newPseudoImage($w, $h, "gradient:$bgFrom-$bgTo");
		$im->setImageFormat("png");
	// Draw coin border
		$draw = new ImagickDraw();
		$draw->setStrokeColor( new ImagickPixel("blue"));
		$draw->setStrokeWidth(4);
		$draw->setFillColor( new ImagickPixel( "green" ) );
		$draw->circle(120, 120, 38, 38);
		$im->drawImage( $draw );
	// Output image
		header("Content-type: image/png"); echo $im; $im->clear(); $im->destroy();
?>
You can see it in action visiting http://nullvoid.org/bitcoin/big/forumex ... =%23FFFFFF

Currently the background is created with a gradient. The circle, however, is solid green with blue border. How can I produce a circle filled with a gradient?

I stumbled upon viewtopic.php?t=8149 and it seems related, but it also from a few years ago and doesn't offer a solution.

Re: drawing with gradients

Posted: 2010-09-15T01:48:56-07:00
by mizerydearia
bump

Re: drawing with gradients

Posted: 2010-09-15T02:35:53-07:00
by Bonzo
I would guess you need to create the gradient on a square image and then create a mask to give you the circle with the gradient.
You would then need to composite the two images.

Re: drawing with gradients

Posted: 2010-09-15T10:18:04-07:00
by fmw42
I don't know if this is what you are looking for, but see radial-gradients at http://www.imagemagick.org/Usage/canvas ... l-gradient

Re: drawing with gradients

Posted: 2010-09-15T18:52:16-07:00
by anthony
linear gradients are posible with draw. But it is not straight forward.

Best idea is to grab the SVG file...
http://www.imagemagick.org/Usage/draw/diagonal.svg
Used for examples in IM examples
http://www.imagemagick.org/Usage/draw/#svg

Now generate the mvg (magick Vector graphics) that this svg produces...

Code: Select all

     convert msvg:diagonal.svg diagonal.mvg
Also shown in that part of IM examples.

This shows how a gradient is defined and used in MVG draw commands.
For a linear gradient in a circle, replace the 'rectangle' draw with a 'circle' draw command.


It is probably time to write up soem examples of drawing with gradients.