// Last updated 2008/11/27 18:09

#include <windows.h>
#include <wand/MagickWand.h>
// convert logo: ( logo: -resize 100%x50%! -size  640x240 \
//		gradient:white-black +matte -compose copyopacity -composite ) \
//		-append logo_reflect.png
void test_wand(void)
{
	MagickWand *mw = NULL,
		// Reflection wand
		*mwr = NULL,
		// gradient wand
		*mwg = NULL;
	int w,h;

	MagickWandGenesis();
	mw = NewMagickWand();
	MagickReadImage(mw,"logo:");
	// We know that logo: is 640x480 but in the general case
	// we need to get the dimensions of the image
	w = MagickGetImageWidth(mw);
	h = MagickGetImageHeight(mw);

	// +matte is the same as -alpha off
	// This does it the "new" way but if your IM doesn't have this
	// then MagickSetImageMatte(mw,MagickFalse); can be used
	MagickSetImageAlphaChannel(mw,DeactivateAlphaChannel);
	// clone the input image
	mwr = CloneMagickWand(mw);
	// Resize it
	MagickResizeImage(mwr,w,h/2,LanczosFilter,1);
	// Flip the image over to form the reflection
	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,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,MagickTrue);

	// and save the result
	MagickWriteImage(mwg,"logo_reflect.png");
	if(mw) mw = DestroyMagickWand(mw);
	if(mwg) mwg = DestroyMagickWand(mwg);
	if(mwr) mwr = DestroyMagickWand(mwr);
	MagickWandTerminus();
}