Page 1 of 1

Creating an 'erase' brush

Posted: 2006-12-21T15:23:46-07:00
by monsters
Hi there,

I'm 'drawing' on an image, like thus

Code: Select all

	DrawSetStrokeColor($drawing,$pixel);
DrawSetStrokeWidth($drawing,$thickness);
DrawSetStrokeAlpha($drawing,$opacity);
DrawSetStrokeLineCap($drawing, MW_RoundCap);
DrawSetStrokeLineJoin($drawing, MW_RoundJoin);
DrawSetFillOpacity($drawing,1);

DrawLine($drawing, 0, 0, 200, 200);
			

MagickDrawImage($source,$drawing);
what i'd like to do is 'erase' part of what i've drawn, i tried this

Code: Select all

DrawLine($drawing, 0, 0, 200, 200);
//set the stroke to transparent
DrawSetStrokeAlpha($drawing,0);
DrawLine($drawing, 0, 200, 200, 0);
but that didn't work of course.. i really just need to be able to set some pixels on my 'drawing' as transparent before applying them back to the main image, .. any suggestions?

I could create a new image with my 'erase' pen, and then apply that as a transparency mask, but i'm having some trouble finding out how to do that as well.

Posted: 2006-12-21T16:56:47-07:00
by anthony
As you discovered you can not 'draw' transparency.

However what you can do is create a second 'transparent' canvas and draw what you want to erase on it. The color of the 'shape' does not matter, as long as it is not transparent where you want things erased. Think of the resulting image as a shaped 'hole punch'.

This image can then be alpha composites over the destination image using 'DstOut', which will then erase that shape from the original image.

See the 'cresent moon' example, in the command line IM examples.
http://www.cit.gu.edu.au/~anthony/graph ... se/#dstout

Which draws one circle, than a second 'hole punch' circle, to erase from the first.

The PHP version of this should be straight forward.