fabricjs

fabricjs - Zoom canvas in viewport (possible?)

ⅰ亾dé卋堺 提交于 2019-12-03 00:19:57
at the moment I try to implement a zoom-functionallity to a visual-editor based on the fabricjs-framework . I've looked around but got more and more confused as I recognized that the development of this feature/function was a long and rocky road for the community and developers. Because of that, many solutions seems to be already outdated. But at the moment I found fabric-viewport developed by the RTSGroup on Github . The implementation was easy, but it only can zoom/control the objects in (inner of) the canvas. Not the canvas too. But I would like to zoom the canvas, too. (inner of the

Select All the objects on canvas using Fabric.js

孤街醉人 提交于 2019-12-03 00:05:16
Is there a way to explicitly select all the objects present at a particular instance of time. This can be easily done using mouse to select all. Is there a code-solution like a button named Select All so that clicking it would make all the fabric type objects being selected and then I could apply the changes to whole of that ActiveGroup using canvas.getActiveGroup(); and iterate over. Good question. There's no built-in method for this, but you would need to do something along these lines: var objs = canvas.getObjects().map(function(o) { return o.set('active', true); }); var group = new fabric

Fabricjs Textbox make the text shrink to fit

允我心安 提交于 2019-12-02 23:24:39
I would define a text box (single-line) By default, with a character size of 16 (for example) When the text gets bigger than the text box, I do not want it to wrap or the text box gets bigger, I want the text size to fit the maximum size of the text box. text. When the text returns to a smaller size, it can resume its initial size (in our example 16). Possibly manage a minimum size If you have an idea, I take :) thanks in advance Test Case : http://jsfiddle.net/Da7SP/273/ // initialize fabric canvas and assign to global windows object for debug var canvas = window._canvas = new fabric.Canvas(

How to make friends Fabric.js and Redux?

*爱你&永不变心* 提交于 2019-12-02 21:22:16
Is there any approach to use Fabric.js and Redux together? Fabric.js state should be used as part of store, but it isn't immutable and can mutate itself by user canvas interaction. Any idea? Thanks. I have extracted small example from my implementation of React-Redux and Fabric.js. It works by simply getting whole fabric object by fabric.toObject(), saving it into state and revoking by fabric.loadFromJSON(). You can play around by using Redux DevTools and traveling through the state. For any case, there is also jsfiddle available: https://jsfiddle.net/radomeer/74t5y1r0/ // don't be scared,

Touch event equivalent to mouse down

邮差的信 提交于 2019-12-02 20:35:20
问题 I'm trying to use a mouse:down event on canvas like: canvas.on('mouse:down', function(options) {} How can I use touchstart event handler? 回答1: I hope this helps // TOUCH EVENTS canvas.addEventListener("touchstart", function (e) { e.preventDefault(); var mousePos = getTouchPos(canvas, e); var touch = e.touches[0]; // do_mouse_click_logic(mousePos.x, mousePos.y, touch.clientX, touch.clientY); }, false); canvas.addEventListener("touchend", function (e) { e.preventDefault(); var mousePos =

Centering and scaling canvas object inside another canvas object by width/height in Fabric.js

无人久伴 提交于 2019-12-02 20:06:49
问题 Goal: To center an object (horizontally and vertically) inside another object (rectangle or group) on canvas via Fabric.js or via Javascript which keeps the original object aspect ratio the same, but also not exceed the parent object width/height proportions? The parent object (rectangle or group) won't be centered on the canvas element. Here's the code I have so far: https://stackblitz.com/edit/angular-my8hky My app.component.ts so far: canvas: fabric.Canvas; ngOnInit() { this.canvas = new

How to drag and drop between canvases in Fabric.js

末鹿安然 提交于 2019-12-02 19:52:14
I understand Fabric.js have built-in support on drag-n-drop within the same canvas. How can we make it work for multiple canvas? Or from an non-canvas html element e.g. an image from a table? Use canvas.observe("object:moving", function (event) {}); If event.e.clientY and event.e.clientX are outside the canvas, then: var activeObject = canvas.getActiveObject(); Store in global dragImage var activeObject.clone(function (c) { dragImage = c; }); canvas.remove(activeObject); Then in window mouse move event you can place an img with src = dragImage.src and follow the cursor. function mousemove(e){

Top-Left coordinates not updated on rotating image using fabricjs

我们两清 提交于 2019-12-02 18:51:52
问题 When I rotate an image in fabricjs, the top-left corner's coordinates are not updated after rotated. Instead, the top-left corner of the image still refers to the old point. I believe that it should recalculate the top-left corner based on the image's new position. Is there a way to achieve this? Any help is appreciated! Below is the code for image rotation: function rotate(){ activeCanvas.forEachObject(function(obj){ if(obj instanceof fabric.Image){ curAngle = obj.getAngle(); obj.setAngle

Saving canvas as a PNG or JPG

佐手、 提交于 2019-12-02 18:13:56
I want to save canvas as PNG, without opening it in a new window as base64-encoded image. I used this code: jQuery("#btnPreview").click(function(){ if (!fabric.Canvas.supports('toDataURL')) { alert('Sorry, your browser is not supported.'); } else { canvas.deactivateAll(); canvas.forEachObject(function(o){ if(o.get("title") == "||Watermark||"){ canvas.bringToFront(o); } }); window.open(canvas.toDataURL('png'), ""); canvas.forEachObject(function(o){ if(o.get("title") == "||Watermark||"){ canvas.sendToBack(o); } }); canvas.renderAll(); } }); I want to make the button save the image as a PNG or

How can I use Fabric.js with React?

落爺英雄遲暮 提交于 2019-12-02 17:16:12
I have an application using heavily HTML5 canvas via Fabric.js . The app is written on top of Angular 1.x, and I am planning to migrate it to React . My app allows writing text and drawing lines, rectangles, and ellipses. It is also possible to move, enlarge, shrink, select, cut, copy, and paste one or more of such objects. It is also possible to zoom and pan the canvas using various shortcuts. In short, my app utilizes Fabric.js to its full extent. I couldn't find much information on how to use Fabric.js together with React, so my concern is that 1. is it possible without major modifications,