Gradient using Magickwand??

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
jumpman25

Gradient using Magickwand??

Post by jumpman25 » 2008-11-06T22:21:50-07:00

I am trying to make a reflection shadow like you see here http://cow.neondragon.net/stuff/reflection/

Is there anyway to do a gradient using Magickwand?

Code: Select all

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

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

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.

el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Gradient using Magickwand??

Post by el_supremo » 2008-11-07T08:54:54-07:00

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.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

jumpman25

Re: Gradient using Magickwand??

Post by jumpman25 » 2008-11-07T20:29:59-07:00

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

<?php
	$mw = NewMagickWand();
	MagickReadImage($mw,"strawberry.png");

	// 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
	MagickResizeImage($mwr,$w,$h/2,MW_LanczosFilter,1);
	MagickFlipImage($mwr); 

	// Create the gradient image which will be used as the alpha
	// channel in the reflection image
	$mwg = NewMagickWand();
	MagickSetSize($mwg,$w,$h/2);
	MagickReadImage($mwg,"gradient:white-black");

	// Copy the gradient in to the alpha channel of the reflection image
	MagickCompositeImage($mwr,$mwg,MW_CopyOpacityCompositeOp,0,0);

	// Add the reflection image to the wand which holds the original image
	MagickAddImage($mw,$mwr);
	// 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');
	MagickEchoImageBlob($mwg);
?>  


el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Gradient using Magickwand??

Post by el_supremo » 2008-11-08T08:21:17-07:00

Earlier versions of IM used:

Code: Select all

	MagickSetImageMatte(mw,MagickFalse);
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

justin

Re: Gradient using Magickwand??

Post by justin » 2008-12-10T15:53:55-07:00

This seems like a great example to start from, but I'm confused by:

MagickReadImage($mwg,"gradient:white-black");

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?

Thanks!

el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Gradient using Magickwand??

Post by el_supremo » 2008-12-10T17:06:44-07:00

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.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

justin

Re: Gradient using Magickwand??

Post by justin » 2008-12-10T17:57:18-07:00

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 http://www.imagemagick.org

el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Gradient using Magickwand??

Post by el_supremo » 2008-12-10T20:34:06-07:00

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.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

justin

Re: Gradient using Magickwand??

Post by justin » 2008-12-11T10:37:54-07:00

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:
http://www.tehuber.com/article.php?stor ... 2101503428

Post Reply