fabricjs

Scale fabric.js canvas objects

余生长醉 提交于 2019-11-29 21:53:26
I have a fabric.js canvas on my page, that I'd like to be responsive. My code works for scaling the canvas itself, but not the objects I've drawn on it. Any idea? I've searched SO but couldn't find a solution that worked for me. var resizeCanvas; resizeCanvas = function() { var height, ratio, width; ratio = 800 / 1177; width = tmpl.$('.canvas-wrapper').width(); height = width / ratio; canvas.setDimensions({ width: width, height: height }); }; Meteor.setTimeout(function() { return resizeCanvas(); }, 100); $(window).resize(resizeCanvas); Here's my zoom function - We zoom the canvas, and then

FabricJS canvas is “stuck” after adding elements

别说谁变了你拦得住时间么 提交于 2019-11-29 20:44:18
问题 I'm creating an application using fabric.js , and experiencing really strange behavior. I'm adding both images and text instances, using the regular fabric.Canvas (not fabric.StaticCanvas ), and am unable to move or resize these items after addition. I've only added a couple of each type. The basic functionality is wrapped in a callback tied to a click event on some button, but the core fabric functionality looks something like this (simplified, but almost everything is the same as far as

Write custom text on image canvas with fabric.js and HTML5

一笑奈何 提交于 2019-11-29 15:43:55
问题 I am using HTML5 and fabric.js for uploading multiple images. I want to add custom text on this image canvas. Right now I am uploading multiple images into canvas one by one. After uploading images I want to add custom text on canvas. var canvas = new fabric.Canvas('canvas'); document.getElementById('file').addEventListener("change",function (e) { var file = e.target.files[0]; var reader = new FileReader(); console.log("reader " + reader); reader.onload = function (f) { var data = f.target

Fabric.js clipping individual objects dynamically

倖福魔咒の 提交于 2019-11-29 11:53:55
I am dynamically adding a rect element to crop/clip (using clipTo) a selected element, It works perfect at the first time but when i add a second element to the canvas and begin to crop the second element the first element looses the crop/clip. Below is my code, there are 2 buttons 1 to start crop/clip (places a dynamic rect over the element to be cropped) second to do the cropping/clipping. $('#crop').on('click', function (event) { var left = el.left - object.left; var top = el.top - object.top; left *= 1; top *= 1; var width = el.width * 1; var height = el.height * 1; object.clipTo =

Fabric.js eraser issue canvas

久未见 提交于 2019-11-29 09:37:29
I want to implement eraser in my web app using Fabric.js. Is there any way to implement eraser in Fabric.js? For example, such as in MS Paint? There's no built-in eraser in Fabric and implementing is a bit difficult. The thing about Fabric is that everything is object-based and most of the things are also vector-based. Unlike with native canvas, we can't just erase some pixels on a global bitmap. We have entire object model underneath, and canvas output is a simple loop of all those objects rendered onto canvas. One way we could emulate eraser is perhaps by having some kind of overlay on top

How to deal with fabric JS image mask?

旧时模样 提交于 2019-11-29 08:57:40
I am trying to implement image mask as example below : Example image here: https://s3-ap-northeast-1.amazonaws.com/utonly/demo/demo.jpg I have tried so many ways and took a lot of time, but still can't find a good solution for it. The image must be able to resizing and rotating inside the mask, or edit from another view, and then apply the result back to the image. I found similar example here http://jsfiddle.net/tbqrn/68/ , but I don't want images pass through each other. Is that possible? Or do I have any chance to try other ways to do this? var img01URL = 'http://fabricjs.com/assets/printio

Lasso tool in html5 canvas

强颜欢笑 提交于 2019-11-29 08:05:46
I'm trying to build a freeform lasso tool to clip an image inside canvas. I'm using fabric.js to draw the shape. var canvas = document.getElementById('c'); var ctx = canvas.getContext('2d'); var img = document.createElement('IMG'); img.onload = function() { var OwnCanv = new fabric.Canvas('c', { isDrawingMode: true }); OwnCanv.freeDrawingBrush.color = "purple" OwnCanv.freeDrawingBrush.width = 4 ctx.clip(); ctx.drawImage(img, 0, 0); } img.src = "http://upload.wikimedia.org/wikipedia/commons/3/33/Jbassette4.jpg?uselang=fi"; <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery

Textbox of Fabric.js does not wrap a long word

放肆的年华 提交于 2019-11-29 07:17:24
I am using the Textbox of Fabric.js . I have given a fixed width. But if a user types a long word without any space that exceeds the given width of textbox, it does not wrap. Any solution? Yes there is a solution that you may like or not to implement word breaking: override the fabric default function for line breaking: fabric.Textbox.prototype._wrapLine = function(ctx, text, lineIndex) { var lineWidth = 0, lines = [], line = '', words = text.split(' '), word = '', letter = '', offset = 0, infix = ' ', wordWidth = 0, infixWidth = 0, letterWidth = 0, largestWordWidth = 0; for (var i = 0; i <

Fabric.js subclassing fabric.Group - Error: “Cannot read property 'async' of undefined” when load from JSON

三世轮回 提交于 2019-11-29 07:10:11
Have the following issue: Trying to subclass fabric.Group: var CustomGroup = fabric.util.createClass(fabric.Group, { type : 'customGroup', initialize : function(objects, options) { options || ( options = { }); this.callSuper('initialize', objects, options); this.set('customAttribute', options.customAttribute || 'undefinedCustomAttribute'); }, toObject : function() { return fabric.util.object.extend(this.callSuper('toObject'), { customAttribute : this.get('customAttribute') }); }, _render : function(ctx) { this.callSuper('_render', ctx); } }); Testcase: I create a red rectangle and added it to

Adding Custom Delete (Back,toFront) Button to Controls

匆匆过客 提交于 2019-11-29 06:20:53
问题 I would like to know if there is an easy way to add a delete, bring to front, bring to back function into the existing fabric.js object controls. At the moment I can only click on buttons which would delete object, bring to front etc. I am working on finding a solution to be able to press X (on the upper right corner) on the object and delete the object. I guess it will have to do with overwriting, wrapping or subclassing the existing control object. Maybe I have overseen something and there