Page 1 of 1

Gradient using Magickwand??

Posted: 2008-11-06T22:21:50-07:00
by jumpman25
I am trying to make a reflection shadow like you see here

Is there anyway to do a gradient using Magickwand?

Code: Select all

MagickNewImage($canvas,500, 600, $bk_color);

//copy and flip image
$add_wand2 = CloneMagickWand($add_wand);

MagickCompositeImage( $canvas, $add_wand, MW_OverCompositeOp, 0, 0);
MagickCompositeImage( $canvas, $add_wand2, MW_OverCompositeOp, 0, 400);
The code does everything for me except to fade the reflection from full color to transparent.

Re: Gradient using Magickwand??

Posted: 2008-11-07T08:54:54-07:00
by el_supremo
I've added an example of this to my MagickWand Examples in C (see URL in my sig).
The reflection is half the height of the original image (just for added effect) but you can omit that step if you like.
The basic reflection is done by creating a white-black gradient and using that as the opacity of the reflection image.


Re: Gradient using Magickwand??

Posted: 2008-11-07T20:29:59-07:00
by jumpman25
thanks el_supremo

however the code seems to hang up on

Code: Select all

MagickSetImageAlphaChannel($mw, MW_DeactivateAlphaChannel);
is there any other way to deactivate the alpha channel in the image?

Code: Select all

	$mw = NewMagickWand();

	// we need to get the dimensions of the image
	$w = MagickGetImageWidth($mw);
	$h = MagickGetImageHeight($mw);

	// +matte is the same as -alpha off
MagickSetImageAlphaChannel($mw, MW_DeactivateAlphaChannel);

	// clone the input image
	$mwr = CloneMagickWand($mw);

	// Resize it and flip the image

	// Create the gradient image which will be used as the alpha
	// channel in the reflection image
	$mwg = NewMagickWand();

	// Copy the gradient in to the alpha channel of the reflection image

	// Add the reflection image to the wand which holds the original image
	// Destroy and reuse $mwg as the result image after the appen
	if($mwg) $mwg = DestroyMagickWand($mwg);

	// Append the reflection to the bottom (MagickTrue) of the original image
	$mwg = MagickAppendImages($mw,true);

	MagickSetFormat($mwg, "png");
	header( 'Content-Type: image/png');

Re: Gradient using Magickwand??

Posted: 2008-11-08T08:21:17-07:00
by el_supremo
Earlier versions of IM used:

Code: Select all


Re: Gradient using Magickwand??

Posted: 2008-12-10T15:53:55-07:00
by justin
This seems like a great example to start from, but I'm confused by:


What's "gradient:white-black" doing?

When I tried it I got:

Fatal error: magickreadimage(): C API cannot read the format "gradient:white-black" (reason: unrecognized color ...

Hey el_supremo your example on your page doesn't link to code by the way?


Re: Gradient using Magickwand??

Posted: 2008-12-10T17:06:44-07:00
by el_supremo
C API cannot read the format "gradient:white-black"
Which version of ImageMagick are you using? In recent versions of ImageMagick this creates an image containing a gradient from white to black.
your example on your page doesn't link to code by the way?
I'm fixing that up right now. Thanks.


Re: Gradient using Magickwand??

Posted: 2008-12-10T17:57:18-07:00
by justin
I'm using PHP MagickWand 1.0.6 and
#:~$ MagickWand-config --version
6.3.7 Q16

#:~$ convert --version
Version: ImageMagick 6.3.7 02/18/08 Q16

Re: Gradient using Magickwand??

Posted: 2008-12-10T20:34:06-07:00
by el_supremo
I think gradients such as the one in my example were alreadyworking in 6.3.7 so I don't know why it would fail for you. The only thing I can suggest is t oupgrade if you can.


Re: Gradient using Magickwand??

Posted: 2008-12-11T10:37:54-07:00
by justin
I finally got 1.0.7 to build, and I just noticed my php_imagick module on the server is version 2.0.1 ( using 2.2.1-dev on my windows machine ).

So, I'm guessing that's the problem. I'll have to uninstall it and compile it instead of using the module from Aptitude.

That's not something I can do over lunch so it'll have to wait until Saturday.

I'm keeping a log of my progress: ... 2101503428