Porting convert command to MagickWand

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
3DTOPO
Posts: 28
Joined: 2010-07-05T16:13:53-07:00
Authentication code: 8675308

Porting convert command to MagickWand

Post by 3DTOPO »

Greetings,

I am trying to port this convert command to the MagickWand API:

Code: Select all

convert ~/input.png  \( +clone -blur 0x6 \) +swap -compose divide -composite  -linear-stretch 15%x0%  ~/output.png
This is what I am doing, but it does not come out the same:

Code: Select all

		
// magick_wand contains the input.png data
MagickWand *blur_wand = CloneMagickWand(magick_wand);
MagickBlurImage(blur_wand, 0.f, 6.f);
MagickSetImageCompose(magick_wand, DivideCompositeOp);

float blackPt = rows * cols * 0.15f;
MagickLinearStretchImage(blur_wand, blackPt, 0.f);	
MagickCompositeImage(magick_wand, blur_wand, DivideCompositeOp, 0, 0);

blur_wand = DestroyMagickWand(blur_wand);
The main thing I am not sure of is what to use for the composite operator. The command line specifies the operator for the compose command but not for the composite command.

I confirmed that the blur and linear stretch both look the same as what is being performed from the convert command, so that makes me suspect the composite command as well.

Any suggestions would be greatly appreciated!
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Porting convert command to MagickWand

Post by el_supremo »

Have a look at my example reflect.c http://members.shaw.ca/el.supremo/Magic ... eflect.htm
It shows the convert command and the equivalent MagickWand code in C and uses clone and compose. That should get you going.
See my signature for other examples.

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.
3DTOPO
Posts: 28
Joined: 2010-07-05T16:13:53-07:00
Authentication code: 8675308

Re: Porting convert command to MagickWand

Post by 3DTOPO »

Thanks, but actually doesn't help.

The code I have is working, I think the issue is I don't know what the equivalent composite operators from the convert command are.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Porting convert command to MagickWand

Post by el_supremo »

Part of the problem is that you're doing the linear stretch before the composite whereas the convert command does it the other way round. You also haven't accounted for the +swap in the convert command.
You need something similar to this:

Code: Select all

// magick_wand contains the input.png data
MagickWand *blur_wand = CloneMagickWand(magick_wand);
MagickBlurImage(blur_wand, 0.f, 6.f);

// Normally, in this situation you would use MagickCompositeImage(magick_wand, blur_wand, ....
// but the easy way to handle the +swap is to put them the other way round as here.
// However, this means that the result is in blur_wand
MagickCompositeImage(blur_wand, magick_wand, DivideCompositeOp, 0, 0);

float blackPt = rows * cols * 0.15f;
MagickLinearStretchImage(blur_wand, blackPt, 0.f);

MagickWriteImage(blur_wand,"~/output.png");

blur_wand = DestroyMagickWand(blur_wand);
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.
3DTOPO
Posts: 28
Joined: 2010-07-05T16:13:53-07:00
Authentication code: 8675308

Re: Porting convert command to MagickWand

Post by 3DTOPO »

BEAUTIFUL! Thank you very very much! I owe you a brew.

That did it! I had tried specifying the blur wand as the first wand for the composite argument, but I didn't try doing the linear stretch after the composite!

So that is what the +swap does! :o

Thanks again! Do you have an iOS device? If so I would be happy to get you some promo codes for our apps...
Post Reply