fabricjs

How to create custom brush paint with fabric.js?

旧城冷巷雨未停 提交于 2019-12-06 17:19:56
问题 I have been trying to create a custom brush paint with an image file using fabric JS . I have tried using the fabric.PatternBrush but this is not the exact thing that I was looking for because this creates a background pattern kind of paint and what I am trying to do is repeat the image wherever the mouse is dragged. Can anyone please direct me towards the right way? It will be fine for me to switch to any other drawing library that does what I am looking for. 回答1: I found a solution to this

Multiple canvases (pages) in Fabric.js

偶尔善良 提交于 2019-12-06 16:58:32
I am trying to create multiple pages as canvases using Fabric.js on click of a button - e.g. every time the button is clicked a new page is created. The problem I'm having is that I want these canvases to use the same functions which are created at when the page is loaded and are only assigned to the initial canvas. Is there a way to create instances of the canvas and still use those same functions? My understanding of your question is that you are creating multiple canvases within a single HTML document. When you are assigning functions to your initial canvas, do you mean they are being added

Emit click events from one canvas to another

∥☆過路亽.° 提交于 2019-12-06 16:28:22
I'm using a Threejs canvas to render a 3d model and another (this one hidden) Fabricjs canvas to apply as a texture. I achieved to transform the 3d coords from the threejs canvas to the 2d canvas. Now what i need is to "replicate" or "emit" the click and drag events from the 3d canvas to the hidden 2d one as suggested in a comment from this question. I made a codepen with my progres. If you click the left canvas a dot will spawn in the same coords but in 2d canvas. I need to be able to click and drag the canvas objects directly from the left threejs canvas. See the codepen i made Codepen <div

Avoid overflow in clip area from canvas fabricjs

老子叫甜甜 提交于 2019-12-06 16:18:04
问题 i am using clip to define drawing area on canvas . when user moves inside object in out defined area then element are not visible but when i save canvas as image they are coming in picture . how can i avoid overflowing ? or restric elements move ?? page screen shot: Saved image :: 回答1: This can be done using two ways: 1) Clipping the the canvas area within a Rectangle canvas.clipTo = function(ctx) { ctx.beginPath(); var rect = new fabric.Rect({ fill: 'red', opacity: 0, left: 0, top: 0, width:

fabric js or imagick remove white from image

不羁岁月 提交于 2019-12-06 15:54:13
I got this situation which is hard for me to search on Google and explain. Our company prints photos on aluminium and we give our customers two choices. The first choice is to print their pictures on aluminium just like they gave the picture to us, so if the picture has a white background the picture gets printed with a white background. Easy like that. The second option is that we can print their picture without using white. instead of all the "white values" (<- the best I can come up with to explain) being printed we leave it transparent. I know there is this removeWhite filter in fabric JS

Fabricjs - how do I deselect an object and select a group without releasing the mouse button

让人想犯罪 __ 提交于 2019-12-06 15:25:49
问题 I have 3 fabric objects on the canvas, a rect and text are grouped as 1 object, then I dynamically create a polygon, and redraw it on object:moving between the group object and another rect. These form what looks like a "speech bubble", with the group and the rect (pointer) both being movable. What I'd like to achieve is: when the polygon is clicked with the mouse, you can move all 3 objects while holding the mouse down. So far what I have groups the items together fine, but you can only move

How do i get point coordinates after object modified?

你说的曾经没有我的故事 提交于 2019-12-06 15:01:54
I would like to get the new point coordinates after object being modified but when i get the points coordinates after being modified they are the same point coordinates with which I have drawn the polygon. Can anyone please tell me why it so? Below is my code, <!--fabricjs --> canvas.on('object:modified', function(e){ var obj=e.target; console.log("new point coordinates "+obj.points); }); Below is the code I used to get the updated points with ROTATE being disabled. But if I get the updated points using below code with rotate option being enabled and after rotating the object, I get wrong set

Fabric.js position elements relative to getZoom() and getWidth()/getHeight()

喜欢而已 提交于 2019-12-06 14:37:18
I am using Fabric.js with React/Redux and i am trying to achieve the following effect on canvas: (note i have 2 rulers on the top and left which shouldn't move around when panning, just horizontally and vertically). This is a video of the effect I am trying to get: https://vid.me/qs5Q I have the following code: var canvas = new fabric.Canvas('c'); var topRuler = new fabric.Text('this is the top ruler', { top: 0, left: 60, selectable: false }); var leftRuler = new fabric.Text('this is the left ruler', { top: 150, left: -125, selectable: false }); var circle = new fabric.Circle({ radius: 20,

Disabling the snapping-grid in fabricjs

帅比萌擦擦* 提交于 2019-12-06 14:32:21
I managed to snap the objects to grid using round-off. canvas.on('object:moving', function(options) { options.target.set({ left: Math.round(options.target.left / grid) * grid, top: Math.round(options.target.top / grid) * grid }); }); How do I disable this, say, on button click? I tried using a flag isGridEnabled and doing: canvas.on('object:moving', function(options) { options.target.set({ left: options.target.left, top: options.target.top }); }); but the object(s) still snap to grid! jkdev Use .off to remove an event handler from a Fabric canvas. I'll quote what kangax (the creator of Fabric

How to freedraw Circle in fabricjs using mouse?

孤人 提交于 2019-12-06 13:52:03
问题 I am using Fabricjs in my project and now working on drawing circle using Fabricjs library. I am able to do it but it is not very proper on x-axis , as dragging on x-axis seems improper whereas dragging on y-axis works fine. Can anybody fix it to work on any axis. Also there are 2-3 questions on stackoverflow that are not properly answered regarding Circle out of which I asked 1 previously. Here's the Fiddle of the work I have done so far: Draw Circle Code : ` var canvas = new fabric.Canvas(