fabricjs2

How to programmatically free draw using Fabric js?

萝らか妹 提交于 2020-05-15 18:53:45
问题 Building a multiplayer doodle using fabric js. Trying to implement multiplayer doodle using fabric js, the idea is when U1 draws on canvas we push the points to RTDB and get those points on both the client and programmatically draw the stroke in both the clients. 回答1: You can save the canvas' data on path:created for example (or other event) using toJSON(). Send it to the server and the other client will load it using loadFromJSON(). var canvas = new fabric.Canvas(document.getElementById(

Limit object resizing

余生长醉 提交于 2019-12-25 01:19:30
问题 I have two Objects on my canvas. The smaller one is on top of the larger one. I want to stop the user from resizing the bigger object to a smaller size than the smaller object. For this I hooked into the bigger objects scaling event: This example only implements it for the left side of the object. function stageIntersectsWithObject() { var stageLeft = el.getBoundingRect(true).left; var objLeft = rect1.getBoundingRect(true).left el.setCoords(); if(stageLeft > objLeft){ el.set('left', objLeft);

FabricJs: Saving and loading dynamic patterns from JSON (patternSourceCanvas)

℡╲_俬逩灬. 提交于 2019-12-11 15:54:43
问题 I am having a problem saving and loading dynamic patterns that are applied to objects. I have searched online for a solution to this to no avail. I understand why it is happening, but do not understand how to resolve it. Here is basically what I am doing... Applying dynamic pattern onto object. Saving the canvas to MongoDB using...'JSON.stringify(canvas.toJSON([...]))' Loading the canvas using 'loadFromJSON' Getting error 'Uncaught ReferenceError: patternSourceCanvas is not defined'

Maintain strokeWidth while scaling in fabric js

[亡魂溺海] 提交于 2019-12-08 15:43:45
问题 Note: I have refereed SO question, but it is not useful for my case, because 1) I am trying to maintain previous border but as of now its recalculate border while scaling. I have added below code to stop increasing border automatically while scaling the object. Now the issue is I have added a 5px border to object but when scaling the object then it is not maintaining the border which I added earlier. canvas.on('object:scaling', (e) => { var o = e.target; if (!o.strokeWidthUnscaled && o

How to create an Editable Text which is curved along a Path in Fabricjs?

吃可爱长大的小学妹 提交于 2019-12-08 07:53:00
问题 I want to make Editable Text which is curved along a fabric.Path as bellow expected image. Here is my code: I created a curved fabric.Path & a fabric.TextBox, but I don't know how to curve text along that Path. Please help me resolve this problem. var canvasObject = document.getElementById("editorCanvas"); // set canvas equal size with div $(canvasObject).width($("#canvasContainer").width()); $(canvasObject).height($("#canvasContainer").height()); var canvas = new fabric.Canvas('editorCanvas'

Line-by-line text background color padding in Fabric JS / Canvas

独自空忆成欢 提交于 2019-12-08 07:05:09
问题 I am using the library FabricJS to overlay text on canvas. I need to add padding (ideally just left & right) to a text element that includes the property textBackgroundColor. Here is what I've tried so far: let textObject = new fabric.Text('Black & White',{ fontFamily: this.theme.font, fontSize: this.theme.size, textBaseline: 'bottom', textBackgroundColor: '#000000', left: 0, top: 0, width: 100, height: 40, padding: 20, fill: 'white', }); The padding doesn't work as I anticipated. I have

Line-by-line text background color padding in Fabric JS / Canvas

試著忘記壹切 提交于 2019-12-08 02:55:29
I am using the library FabricJS to overlay text on canvas. I need to add padding (ideally just left & right) to a text element that includes the property textBackgroundColor. Here is what I've tried so far: let textObject = new fabric.Text('Black & White',{ fontFamily: this.theme.font, fontSize: this.theme.size, textBaseline: 'bottom', textBackgroundColor: '#000000', left: 0, top: 0, width: 100, height: 40, padding: 20, fill: 'white', }); The padding doesn't work as I anticipated. I have attempted to use the backgroundColor property but that adds background to the whole group block and not

How to create an Editable Text which is curved along a Path in Fabricjs?

萝らか妹 提交于 2019-12-07 01:18:29
I want to make Editable Text which is curved along a fabric.Path as bellow expected image. Here is my code: I created a curved fabric.Path & a fabric.TextBox, but I don't know how to curve text along that Path. Please help me resolve this problem. var canvasObject = document.getElementById("editorCanvas"); // set canvas equal size with div $(canvasObject).width($("#canvasContainer").width()); $(canvasObject).height($("#canvasContainer").height()); var canvas = new fabric.Canvas('editorCanvas', { selectionLineWidth: 2, width: $("#canvasContainer").width(), height: $("#canvasContainer").height()