Command Line equivalent for MagickWand API

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
kamila

Command Line equivalent for MagickWand API

Post by kamila »

Can anyone help me out to convert these command line codes to MagickWand API?

convert input.jpg -format "%[fx:mean]" info:
convert xc: -format "%[fx:mean]" info:
convert input.jpg -function polynomial "10,-5.0" output.jpg

Thank you in advance,
Kamila
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Command Line equivalent for MagickWand API

Post by el_supremo »

I thought the first two would be easy but I'm having trouble replicating the values that I get from the command line.
If I sort it out I'll post them later.

Here's a C function which does the third command.

Code: Select all

// convert input.jpg -function polynomial "10,-5.0" output.jpg
// Remove this next line if you're using Linux
#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(LPTSTR lpCmdLine)
{
	MagickWand *mw = NULL;
	double args[2] = {10,-5.0};

	MagickWandGenesis();
	mw = NewMagickWand();

	MagickReadImage(mw,"input.jpg");
	MagickFunctionImage(mw,PolynomialFunction,2,args);
	MagickWriteImage(mw,"output.jpg");
	
	DestroyMagickWand(mw);
	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.
kamila

Re: Command Line equivalent for MagickWand API

Post by kamila »

Thank you for your help on the 3rd one. Looking forward to first & second...
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Command Line equivalent for MagickWand API

Post by el_supremo »

Here's the code to match the first command. For the second command just change "input.jpg" to "xc:" and recompile.

Code: Select all

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

void test_wand(LPTSTR lpCmdLine)
{
	MagickWand *mw = NULL;
	double mean,sd;
	char info[128];

	MagickWandGenesis();
// convert input.jpg -format "%[fx:mean]" info:
	mw = NewMagickWand();

	MagickReadImage(mw,"input.jpg");
	MagickGetImageChannelMean(mw,RedChannel,&mean,&sd);
	// [fx:mean] prints the normalized mean of the Red channel
	// But the MagickWand function returns the unnormalized mean
	// so divide by 65535 to match what the convert command prints
	sprintf(info,"logo: mean = %12g",mean/65535);
	MessageBox(NULL,info,"",MB_OK);
	DestroyMagickWand(mw);

	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.
kamila

Re: Command Line equivalent for MagickWand API

Post by kamila »

el_supremo, you're a lifesaver! thank you so much for your help!

I have one more command line that I can't figure out to convert to API.
I'd really appriciate if you can take a look at this too.

convert img1.jpg img2.jpg -compose vivid_light -composite output.jpg

Thanks in advance!
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Command Line equivalent for MagickWand API

Post by el_supremo »

You just read the two images and then do:

Code: Select all

	MagickCompositeImage(mw,mw1,VividLightCompositeOp,0,0);
where mw is the wand for img1.jpg and mw2 is the wand for img2.jpg.

For more examples of MagickWand see the link in my signature.
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.
kamila

Re: Command Line equivalent for MagickWand API

Post by kamila »

I'll check out your examples for sure...
Thanks a lot again!
Post Reply