Crop Functionality using FabricJs

(This answer is an iteration on the fiddle in Tom’s answer. Thank you, Tom, for getting me down the road.) You can crop in Fabric.js using either fabric.Object.clipTo() or fabric.Object.toDataURL(). The clipTo() method retains the original image and displays a crop via a mask. The toDataURL() method creates a new image. My full example uses … Read more

How does transforming points with a transformMatrix work in fabricJS?

Not really a geometric problem. The geometric part was solve by you. If you would look at internal polygon class from fabricjs you would notice that polygon as a calcDimension function where every point gets an offset: http://fabricjs.com/docs/fabric.Polygon.html To calculate canvas position you have to add that offset back before transforming. var canvas = new … Read more

Snap edges of objects to each other and prevent overlap

I solved the problem on my own. See jsfiddle: http://jsfiddle.net/gcollect/FD53A/ This is the code: this.canvas.on(‘object:moving’, function (e) { var obj = e.target; obj.setCoords(); //Sets corner position coordinates based on current angle, width and height canvas.forEachObject(function (targ) { var objects = this.canvas.getObjects(), i = objects.length; activeObject = canvas.getActiveObject(); if (targ === activeObject) return; if (Math.abs(activeObject.oCoords.tr.x – … Read more

canvas.toDataURL() for large canvas

I’m not sure if there are limitation to canvas dimensions, but data urls have limitations depending on the browser: Data URL size limitations. What you could try is using Node.js + node-canvas (server side) to recreate the canvas. I’ve been using these for creating printable images from canvas elements, and didn’t have any problems/limitations using … Read more