Multiple clipping areas on Fabric.js canvas

前端 未结 7 1531
一生所求
一生所求 2020-11-28 04:26

For making Photo Collage Maker, I use fabric js which has an object-based clipping feature. This feature is great but the image inside that clipping region cannot be scaled,

7条回答
  •  北海茫月
    2020-11-28 05:19

    This can be done much more easily. Fabric provides render method to clip by the context of another object.

    Checkout this fiddle. I saw this on a comment here.

    obj.clipTo = function(ctx) {
        ctx.save();
        ctx.setTransform(1, 0, 0, 1, 0, 0);
    
        clippingRect.render(ctx);
    
        ctx.restore();
    };
    

提交回复
热议问题