Page 1 of 1

How to add mask in magickhand (php)

Posted: 2007-01-05T05:22:00-07:00
by vilords

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.


Posted: 2007-01-06T12:14:29-07:00
by *void
The following discussion of extracting a mask using the command line should help you see some techniques: ... 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.

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

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

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.


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

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

IM_output("JPG"); (my function)

Any idea?

Posted: 2007-01-06T15:19:20-07:00
by vilords
Hmm, my fault...used the wrong command.

I'll try with MagickCompositeImage now.

Posted: 2007-01-06T15:41:17-07:00
by vilords
ok...fixed it, but all I see is a black square on the image:


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

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


Posted: 2007-01-06T15:59:34-07:00
by el_supremo
I'm not sure which composite operator you need but it might work with DstIn instead of DstOut.


Posted: 2007-01-06T16:12:58-07:00
by vilords
hmm, doesn't seem to work.... just puts one image into another


Posted: 2007-01-09T16:08:14-07:00
by vilords
:) already figured it out...

Posted: 2007-01-09T16:45:19-07:00
by el_supremo
Would you mind explaining what you did?


Re: How to add mask in magickhand (php)

Posted: 2008-11-05T14:14:54-07:00
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