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 » 2007-01-05T05:22:00-07:00

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 » 2007-01-06T12:14:29-07:00

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 » 2007-01-06T12:52:29-07:00

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 » 2007-01-06T13:42:28-07:00

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 » 2007-01-06T15:15:09-07:00

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 » 2007-01-06T15:19:20-07:00

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

I'll try with MagickCompositeImage now.

vilords

Post by vilords » 2007-01-06T15:41:17-07:00

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 » 2007-01-06T15:59:34-07:00

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

Pete

vilords

Post by vilords » 2007-01-06T16:12:58-07:00

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

:(

vilords

Post by vilords » 2007-01-09T16:08:14-07:00

:) already figured it out...

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

Post by el_supremo » 2007-01-09T16:45:19-07:00

Would you mind explaining what you did?

Pete

QooooQ

Re: How to add mask in magickhand (php)

Post by QooooQ » 2008-11-05T14:14:54-07:00

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