Watermarking image

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
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Post by el_supremo » 2006-04-01T11:28:39-07:00

Not sure if this is exactly what you're after but this code will read two images and use the Dissolve operator to composite one image over the other.
I've put the two images on my webpage so that this code will fetch them directly. This code was written on windows but with minor changes should work on other OS.


Code: Select all

#include <windows.h>
#include <wand/magick_wand.h>
// To get definition of magickwand  for magick_wand->images
#include <wand/magick-wand-private.h>

void test_wand(void)
	MagickWand *magick_wand = NULL,*moth_wand = NULL;
	double comp_opacity,moth_opacity;
	Quantum c_opacity,m_opacity;

		For detailed info about MagickWand functions and their parameters see:

	/*	When comp_opacity is 0.0:
		moth_opacity = 1.0 completely invisible
		moth_opacity = 0.0 fully visible
		I've used doubles to specify the opacities and then I translate these into
		Quantum values. You can use Quantum values directly.
	comp_opacity = 0.0;
	/* The moth will be partially visible */
	moth_opacity = 0.6;

	/* convert the (double) opacities to Quantum for the setimageopacity 
		I'm using a Q8 version so a Quantum will be an unsigned char and
		QuantumRange will be 255 

	c_opacity = (Quantum)RoundToQuantum((MagickRealType)comp_opacity * QuantumRange);
	m_opacity = (Quantum)RoundToQuantum((MagickRealType)moth_opacity * QuantumRange);

	// The Big Bang

	magick_wand = NewMagickWand();
	// Read the image from the web.
	// Strip any profiles, thumbnails etc.
	/* for the setimageopacity function I want the matte to be off so that
		opacity is *set*. If matte is already on then it is *blended*.
		So, force the opacity off (just in case I've read a PNG or other format
		which does have a matte layer). Then use SetImageOpacity to force matte on 
		and set the opacity value
	// Set the opacity of the background to c_opacity and turn matte on.

	moth_wand = NewMagickWand();

	// Do the same with the matte and opacity in the overlay image
	/* Turn matte on and set opacity of the moth image to m_opacity */

	// and do the Dissolve composite operation

	// Write the image 

	/* Clean up */
	if(magick_wand)magick_wand = DestroyMagickWand(magick_wand);
	if(moth_wand)moth_wand = DestroyMagickWand(moth_wand);

	// Armageddon

Post Reply