javascript - Creating a path from a PNG in fabricjs -


  • i have png image transparent area.
  • i have photo.
  • i using fabricjs

i need create new image cropped transparent area of png.

i understand can use clipto(path) function create new image.

however, problem creating path in first place. how can create path transparent area of png?

thanks in advance.

as strange may seem, wasn't able find correct duplicate this...


you don't need calculate path bitmap. canvasrenderingcontext2d api offers compositing , blending options, allow work directly bitmaps.

fabricjs offers option: http://fabricjs.com/docs/fabric.object.html#globalcompositeoperation

var c = new fabric.canvas('c', {    imagesmoothingenabled: false  });  fabric.image.fromurl(    'https://dl.dropboxusercontent.com/s/4e90e48s5vtmfbd/aaa.png',    function(image1) {     fabric.image.fromurl(      'https://upload.wikimedia.org/wikipedia/commons/5/55/john_william_waterhouse_a_mermaid.jpg',      function(image2) { // 1 clipped        c.add(image1);        c.add(image2);        c.renderall();     }, {      globalcompositeoperation: 'source-in', // drawn pixels drawn      top: -300,      left: -400    });    }, {    width: 200,    height: 200  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.18/fabric.js"></script>  <canvas id="c" width="500" height="500"></canvas>


Comments

Popular posts from this blog

minify - Minimizing css files -

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -