I want to make a hole inside of polygon with fabricjs
. I can make it using normal html5 canvas with counter-clockwise as shown below, but I would prefer to make it using fabricjs
. Does anyone know how to implement the attached image using 'fabriicjs'?
Like this:
Here's one way to draw a cutout-polygon onto FabricJS:
AFAIK, FabricJS does not yet support the compositing necessary to create cutouts from its polygons, so here's a workaround.
Draw the cutout polygon onto an html5 canvas. For example
.globalCompositeOperation='destination-out'
. This will cause all new drawings to act as an "eraser" and will cut out any existing pixels under the new drawings.Use the html5 canvas as an image source for a new
Fabric.Image
.