fabricjs

How to setup the Fabric.js?

帅比萌擦擦* 提交于 2019-12-06 03:35:53
问题 I am very new to fabric.js. I have downloaded the fabric.js, but I don't know how to start it. For example: <html> <head> <script src="fabric.min.js"></script> </head> <body> <canvas id="canvas" width="800" height="450" style="border:1px solid #000000"></canvas> <script> var canvas = new fabric.Canvas('c1'); canvas.add(new fabric.Circle({ radius: 30, fill: '#f55', top: 100, left: 100 })); canvas.selectionColor = 'rgba(0,255,0,0.3)'; canvas.selectionBorderColor = 'red'; canvas

How to select child elements after using groupSVGElements

倖福魔咒の 提交于 2019-12-06 03:33:48
I am loading an svg into Fabric which has child elements. I'm grouping them using groupSVGElements(). I need to be able select each child element - that is an onclick event that allows me to select a child object. I've thrown together this fiddle http://jsfiddle.net/AnQW5/2/ Although I can list out the child objects of the group via getObjects, theres no way that I can see to determine which object was clicked. So : canvas.observe('object:selected', function(e) { console.log(e.target.getObjects()); // ??? }); Any ideas? You can use canvas.add.apply instead groupSVGElements, so you can : have

Maintaining object size while zooming in fabric js

五迷三道 提交于 2019-12-06 02:02:49
Is there any solution for maintaining object size even if the user zoom in or out? I want to achieve like on the google maps behavior. So if I have an object (group of object) with a height and width of 20 even if I zoom into it, it should still be 20 pixels by default. Right now the behavior I have is that when the user zoom in or out the image gets bigger / smaller. I also did looping all the objects that I have on the canvas then set the scaleX and scaleY for it but the result was so laggy for me. var canvas = new fabric.Canvas('c') ; var circle = new fabric.Circle({ radius: 20, fill: 'red'

Base64 image data not working with loadfromJSON in fabricjs

北城以北 提交于 2019-12-06 01:42:02
问题 I am trying to load a json object which has a image object. Image object is having base 64 image data as background. But i am unable laod the loadFromJSON method. Code: var jsonDataSet = '{"objects":[{"type":"image","originX":"left","originY":"top","left":0,"top":0,"width":700,"height":600,"fill":"rgb(0,0,0)","overlayFill":null,"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX"

Fabricjs intersectsWithObject returning false when Object is fabric.Rect

时光怂恿深爱的人放手 提交于 2019-12-06 00:39:19
问题 I'm trying to determine when a fabric.Rect overlaps another fabric.Rect while observing the 'object:moving' event but having inconsistent results between fabric.Group vs fabric.Rect When I move Group over a Rect instance the intersectsWithObject method returns true, but when I'm moving a Rect instance over another Rect instance it returns false. I'm wondering if I'm doing something wrong here. Here's my event handler cvs.observe('object:moving', function(e) { var targ = e.target; // filter

get rgb values of pixel of image in fabric.js on mouse move

狂风中的少年 提交于 2019-12-05 23:55:13
问题 how to get rgb values of image in fabric.js on mouse move. I used getFill() method of image object, but it is returning (0,0,0). Please help me 回答1: FabricJS does not have a native method for getting the pixel colors. The workaround is to use native html5 canvas to fetch the pixel data: Create your Fabric image objects. Be sure to specify crossOrigin as 'anonymous' otherwise the canvas will be tainted with a security violation and then the pixel data will be unavailable. Listen on Fabric's

Uploading an image from computer to Fabric.JS Canvas

青春壹個敷衍的年華 提交于 2019-12-05 23:54:13
Are there any Fabric.JS Wizards out there? I've done my fair research and I can't seem to find much of an explanation on how to add an image to the fabric.JS canvas. User Journey: a) User uploads an image from an input file type button. b) As soon as they have selected an image from their computer I want to place it into the users canvas. So far I've got to storing the image into an expression, this is my code below: scope.setFile = function(element) { scope.currentFile = element.files[0]; var reader = new FileReader(); /** * */ reader.onload = function(event) { // This stores the image to

fabric.js … how to center canvas

徘徊边缘 提交于 2019-12-05 20:41:25
问题 fabricjs will convert: // this DOM structure <div id="wrapper"> <canvas id="c"></canvas> </div> // to this: <div id="wrapper"> <div class="canvas-container"> <canvas class="upper-canvas"></canvas> <canvas class="lower-canvas" id="c"></canvas> </div> </div> ... see this explanation Because of the way fabric js wraps a canvas element, how do you keep a canvas horizontally centered. here is similar question. here is a fiddle test 回答1: apply margin: 0 auto; to class = canvas-container canvas

node-canvas build for AWS Lambda

流过昼夜 提交于 2019-12-05 18:24:14
I'm a Linux & node noob. I'm trying to run FabricJS (which requires node-canvas) in AWS Lambda. I've been able to follow the instructions to get up and running on an AWS Linux EC2, however, Lambda has me at my wits end. Anyone have any tips or pointers on how to get this compiled for AW Lambda? I found this issue in the Node Canvas GitHub site . The questioner was trying to run FabricJS in Lambda as well. Here is the relevant section with an answer: Make sure you're compiling this on the same AMI that lambda currently uses: http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions

Drag Fabric.js object from one canvas to another

帅比萌擦擦* 提交于 2019-12-05 18:04:15
I am using Fabric.js to create design on any product. my some product has two canvas so I want to move fabric.Text from one canvas to another and I want to drag and drop Fabric canvas object to other Fabric canvases. I have absolutely no idea whether this is a good, bad or ugly way of doing things however I've put together a simple fiddle which achieves what you are after - the basic principle of what i've done is this: encapsulate your canvas objects within an object, where the canvas id's are the object keys, for example var canvases = { canvas1 : new fabric.Canvas('canvas1'), canvas2 : new