fabricjs

How to create custom brush paint with fabric.js?

感情迁移 提交于 2019-12-04 20:57:09
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. I found a solution to this problem. We can create a custom brush using fabric.BaseBrush as follows: fabric.SprayBrush = fabric.util

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

人盡茶涼 提交于 2019-12-04 20:38:42
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 all the items if you select the polygon, then release the mouse button , then click the group again ,

Saving JSON in canvas with fabric.js

寵の児 提交于 2019-12-04 19:17:52
I am trying to import multiple svg file and after modification saving the json to database. I have tried to use canvas.item(0).sourcePath = '/URL/FILE.svg'; JSON.stringify(canvas.toDatalessJSON()); but this won't work for multiple files, it works for the first file only. i am trying to specify every single file url but can't understand how this can be done. any solution please? thanks in advance canvas.item(0) - gets the first object. canvas.item(1) - gets the second object and so on.... If you don't know the total amount of objects you can use the canvas.forEachObject option. canvas

FabricJS image object clipTo shape object issue

断了今生、忘了曾经 提交于 2019-12-04 18:55:42
Why this clipTo method doesn't work on the latest fabricjs version, which you could resize the object container and the image inside it. Also you able to move the container object and image object. var imgInstance = new fabric.Image(img, { width: instanceWidth, height: instanceHeight, top: (canvas.getHeight() / 2 - instanceHeight / 2), left: (canvas.getWidth() / 2 - instanceWidth / 2), originX: 'left', originY: 'top' }); canvas.add(imgInstance); imgInstance.clipTo = function(ctx) { /* image clipping method doesn't work on latest fabricjs version*/ ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0)

Issue with object while restricting it to canvas boundary

南楼画角 提交于 2019-12-04 17:43:41
I am currently running with my project and in that i have used fabric js to work with canvas. In that i want my canvas object not to go out of canvas boundary.I did this code and it is working fine unless and until i am rotating it. but when i am rotating the object, top left of that object is getting as per rotation and my code is not working well. I want some solution which will work in any condition but my object should not go outside of canvas boundary. Thanks var canvas=new fabric.Canvas('demo'); canvas.on('object:moving',function(e){ if(e.target.getWidth()+e.target.left>canvas.width) { e

Control z-index in Fabric.js

我的未来我决定 提交于 2019-12-04 16:48:54
问题 In fabricjs, I want to create a scene in which the object under the mouse rises to the top of the scene in z-index, then once the mouse leaves that object, it goes back to the z-index where it came from. One cannot set object.zindex (which would be nice). Instead, I'm using a placeholder object which is put into the object list at the old position, and then the old object is put back in the position where it was in the list using canvas.insertAt. However this is not working. See http:/

toSVG method not working on extended class with Fabric.js

假如想象 提交于 2019-12-04 16:48:34
I'm working on a project with Fabric.js. Now I need to create a custom class and to export it to SVG. I'm using Fabric.js tutorial to begin: http://www.sitepoint.com/fabric-js-advanced/ Here is the javascript code: var LabeledRect = fabric.util.createClass(fabric.Rect, { type: 'labeledRect', initialize: function(options) { options || (options = { }); this.callSuper('initialize', options); this.set('label', options.label || ''); }, toObject: function() { return fabric.util.object.extend(this.callSuper('toObject'), { label: this.get('label') }); }, _render: function(ctx) { this.callSuper('

Restrict area for draw image object in canvas HTML5

拥有回忆 提交于 2019-12-04 15:58:29
I want to restrict area for uploaded image in canvas. I am using fabric js to achieve this solution. I have seen one link, But did not get idea. that link is: Set object drag limit in Fabric.js . I also want to same thing, But i am not able to do this one. what i want? i will show in screen shot. var canvas = new fabric.Canvas('canvas'); $("#canvascolor > input").click(function() { canvas.setBackgroundImage(this.src, canvas.renderAll.bind(canvas), { crossOrigin: 'anonymous' }); }); // trigger the first one at startup $("#canvascolor > input:first-of-type()")[0].click(); document.getElementById

FabricJs - How do I Add properties to each object

大憨熊 提交于 2019-12-04 12:51:17
问题 I need to introduce few additional properties to existing object properties set. like: ID Geo Location etc Whenever I draw a shape, I need to add additional properties to the shape and need to get from toDataLessJSON() 回答1: As of version 1.7.0 levon's code stopped working. All you need to do is to fix as follows: // Save additional attributes in Serialization fabric.Object.prototype.toObject = (function (toObject) { return function (properties) { return fabric.util.object.extend(toObject.call

Fabricjs Youtube Video

霸气de小男生 提交于 2019-12-04 12:36:53
问题 I'm using fabricjs to load videos inside canvas, it works fine with normal mp4 videos like this: <canvas id="c" width="1024" height="600" style="border:1px solid black;" ></canvas> <video width="350" height="220" id="video1" style="display: none"> <source src="http://html5demos.com/assets/dizzy.mp4"> <source src="http://html5demos.com/assets/dizzy.ogv"> </video> var video1El = document.getElementById('video1'); var video1 = new fabric.Image(video1El, { left: 270, top: 250, angle: -15, originX