How to add mask in magickhand (php)

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
vilords

How to add mask in magickhand (php)

Post by vilords »

Hi,

1, I imported image
2, created a rectangle with rounded edges

Now, I would like to use the rectangle as a mask.

How may I do that using magickwand?

There is a matte command....when doing that via command line, but not sure how to do it here.

Please help.

Paul
*void

Post by *void »

The following discussion of extracting a mask using the command line should help you see some techniques:
http://www.cit.gu.edu.au/~anthony/graph ... s/#extract

The last technique (colorize then flatten) looks especially easy. I don't know how to translate any of it into MagickWand for PHP.
vilords

Post by vilords »

I know, I studied pretty much everything Anthony has on the site.

The problem is, I have no clue how to do that using MagickWand :)
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Post by el_supremo »

I don't know how to do this in PHP and I haven't used that specific technique in C, but I think the command you need will look something like this C function:

Code: Select all

MagickCompositeImage(magick_wand,mask_wand,DstOutCompositeOp,0,0);
where magick_wand is the imported image and mask_wand is, of course, the mask image. The 0,0 on the end is the x,y offset coordinates.

Pete
vilords

Post by vilords »

Yes, that's gotta be it...doesn't seem to work though, I tried following..and all I got is the picture.

I use following script:

IM_fileopen('../../tmp/1b.jpg'); (my function)

DrawRectangle($dwand, 50, 50, 100, 100);
DrawSetFillColor($dwand,$pwand);

$width = MagickGetImageWidth($resource);
$height = MagickGetImageHeight($resource);
DrawComposite($dwand, MW_DstOutCompositeOp, 0, 0, $width, $height, $resource);

IM_output("JPG"); (my function)

Any idea?
vilords

Post by vilords »

Hmm, my fault...used the wrong command.

I'll try with MagickCompositeImage now.
vilords

Post by vilords »

ok...fixed it, but all I see is a black square on the image:

IM_fileopen('../../tmp/1b.jpg');

MagickSetSize($resource2, 100, 100);
MagickReadImage($resource2, "xc:none");
DrawRectangle($dwand, 50, 50, 100, 100);
DrawSetFillColor($dwand,$pwand);
MagickDrawImage($resource2,$dwand);

MagickCompositeImage($resource, $resource2, MW_DstOutCompositeOp, 0, 0);

IM_output("JPG");
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Post by el_supremo »

I'm not sure which composite operator you need but it might work with DstIn instead of DstOut.

Pete
vilords

Post by vilords »

hmm, doesn't seem to work.... just puts one image into another

:(
vilords

Post by vilords »

:) already figured it out...
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Post by el_supremo »

Would you mind explaining what you did?

Pete
QooooQ

Re: How to add mask in magickhand (php)

Post by QooooQ »

Oh man, how I hate those guys telling you they figured something out.... as if it would interest anybody.

Either someone knows better then you.... then he doesn't care.
Or he doesn't know better.... then he doesn't care, too.

I mean whats the stupid meaning of this sentence when there's no solution next to it.

That's something one could care about. Grrrr

<=== don't take this to serious :D
Post Reply