Basic help to get mestarted

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
rray

Basic help to get mestarted

Post by rray »

I am a long time C programmer but a MagickWand virgin.
Are there man pages for api functions?
"composite -depth 8 -dissolve 15 -gravity center stamp.png source.png destination.png"
Could someone give me a bit of starter code that would accomplish this using MagickWand?
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Basic help to get mestarted

Post by el_supremo »

The code below should do what you want. It uses a method described by Anthony near the end of this topic

Also see the examples at the URL in my sig.

Pete

Code: Select all

#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(LPTSTR lpCmdLine)
{
	MagickWand *magick_wand = NULL,*sig_wand = NULL;
	// dimensions of source image
	long sw,sh;
	// dimensions of stamp (signature) image
	long tw,th;

	/* 
		For detailed info about MagickWand functions and their parameters see:
		http://studio.imagemagick.org/script/magick-wand.php
	*/

	MagickWandGenesis();

	magick_wand = NewMagickWand();
	// Read the image
	MagickReadImage(magick_wand,"source.png");
	// Get the dimensions of the image
	sw = MagickGetImageWidth(magick_wand);
	sh = MagickGetImageHeight(magick_wand);
	// Strip any profiles, thumbnails etc.
	MagickStripImage(magick_wand);
	MagickSetImageMatte(magick_wand,1);

	// read the stamp (signature) image
	sig_wand = NewMagickWand();
	MagickReadImage(sig_wand,"stamp.png");
	tw = MagickGetImageWidth(sig_wand);
	th = MagickGetImageHeight(sig_wand);
	MagickStripImage(sig_wand);

	// Set the sig file's opacity to 15%
	MagickEvaluateImageChannel(sig_wand,AlphaChannel,MultiplyEvaluateOperator,0.15);
	// do the Over composite operation and place the stamp image in the centre of the source
	MagickCompositeImage(magick_wand,sig_wand,OverCompositeOp,(sw-tw)/2,(sh-th)/2);
	// Set the depth to 8
	MagickSetImageDepth(magick_wand,8);
	// Write the image 
	MagickWriteImage(magick_wand,"destination.png");

	/* Clean up */
	if(magick_wand)magick_wand = DestroyMagickWand(magick_wand);
	if(sig_wand)sig_wand = DestroyMagickWand(sig_wand);
	
	MagickWandTerminus();
}
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.
rray

Re: Basic help to get mestarted

Post by rray »

Very nice examples
This should get me started
I do miss the man pages
Thanks
rray

Re: Basic help to get mestarted

Post by rray »

I think the documentation needs a bit of clarification
Your code has " MagickEvaluateImageChannel(sig_wand,AlphaChannel,MultiplyEvaluateOperator,0.15);"
Four arguments

The documentation at "http://imagemagick.org/api/magick-image.php" says
MagickBooleanType MagickEvaluateImageChannel(MagickWand *wand, const MagickEvaluateOperator op,const double value)
Three arguments

I would have never figured this out without your code for reference

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

Re: Basic help to get mestarted

Post by el_supremo »

Yes, there's a documentation error in both MagickEvaluateImageChannel and MagickFunctionImageChannel. Neither function describes that it requires a Channel argument.

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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Basic help to get mestarted

Post by anthony »

Report it as a bug if the documentation is wrong. Better yet provide replacement text that can be just copy and pasted into place. :-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply