fabricjs

How can I use Fabric.js with React?

别说谁变了你拦得住时间么 提交于 2019-11-28 16:40:18
问题 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

How do i get the coordinates of vertices of shapes instead of the control corners coordinates in fabric js?

五迷三道 提交于 2019-11-28 13:12:40
The following code gives me coordinates of control corners but I want to calculate the coordinates of vertices of triangle, pentagon, hexagon etc., <!-- fabric js function to return coordinates--> function getCoords(oCoords) { return { tl: new fabric.Point(oCoords.tl.x, oCoords.tl.y), tr: new fabric.Point(oCoords.tr.x, oCoords.tr.y), bl: new fabric.Point(oCoords.bl.x, oCoords.bl.y), br: new fabric.Point(oCoords.br.x, oCoords.br.y) } } <!--fabric js event handler--> canvas.on('mouse:move', function(e){ console.log('over1',e.target) if(e.target && e.target !== canvas.getActiveObject()) canvas

How to render a 5MB image onto canvas by reducing height and width

杀马特。学长 韩版系。学妹 提交于 2019-11-28 13:01:48
问题 I am using fabricjs to render images but the images that I have are very large near to 5 MB or even more. For example I have a image having 2130*1800 (width*height) and my canvas width and height ,that I can afford at max is 90% of window.width*90% of window.height . How can I do that ? 回答1: Here is the jsFiddle example : https://jsfiddle.net/CanvasCode/7oghuwe2/3/ Javascript var imageRatio = image1.width / image1.height; var newHeight = canvas1.width / imageRatio; var newWidth = canvas1

Adding canvas inside another canvas: obj.setCoords is not a function( fabric js)

回眸只為那壹抹淺笑 提交于 2019-11-28 12:00:19
Started using fabric.js and trying to add a canvas inside another canvas, so that the top canvas stays constant and I'll add objects to inner canvas. Here is the snippet of adding a canvas to another canvas. canvas = new fabric.Canvas('artcanvas'); innerCanvas = new fabric.Canvas("innerCanvas"); canvas.add(innerCanvas); and my html looks like this <canvas id="artcanvas" width="500" height="500"></canvas> <canvas id="innerCanvas" width="200" height="200" ></canvas> Once adding these successfully, what I am going to do is , add the coordinates to the inner canvas, so that it looks like one on

Fabric.js - problem with drawing multiple images zindex

℡╲_俬逩灬. 提交于 2019-11-28 11:31:56
I'm using this script: var canvas = new fabric.Canvas('game_canvas', { selection: false }); fabric.Image.fromURL('images/bg.jpg', function(img) { img.set('left', 1024/2).set('top', 600/2).set('zindex', 0); canvas.add(img); }); fabric.Image.fromURL('images/panel-2-bg-l-r.png', function(img) { img.set('left', 262/2).set('top', (390/2)+110).set('zindex', 1); canvas.add(img); }); fabric.Image.fromURL('images/player-board.png', function(img) { img.set('left', 254/2).set('top', (122/2)).set('zindex', 2); canvas.add(img); }); fabric.Image.fromURL('images/player-board-top-red.png', function(img) { img

How to get polygon points in Fabric.js

冷暖自知 提交于 2019-11-28 10:34:24
I am drawing polygon by capturing mouse clicks on canvas and then passing these points to fabric.Polygon . So, in this manner I'm drawing multiple polygons. What I need know is, I want to get the mouse co-ordinates (pixel points on canvas) for the polygon which is selected now? I have tried with: canvas.getActiveObject().get('points'); But this is giving some negative and some positive values. So, can u please tell me a way to find out the polygon points? Polygon points are relative to its center so you can get their "absolute" position like so: var polygon = canvas.getActiveObject(); var

Crop Functionality using FabricJs

时光怂恿深爱的人放手 提交于 2019-11-28 08:19:57
How to implement crop tool on the image that is loaded on the canvas using fabric.js ? I have a image loaded on the canvas .Now i want to implement crop tool where the user is allowed to crop the image and reload it on to the canvas when he is done. Tom In Summary set el.selectable = false draw a rectangle on it with mouse event get rectangle left/top and width/height then use the following function Sorry, let me explain. The ctx.rect will crop the image from the center point of the object. Also the scaleX factor should be taken into account. x = select_el.left - object.left; y = select_el.top

How to use Fabric.js to do Visio like drawings with connections?

Deadly 提交于 2019-11-28 06:38:13
I've recently started to use Fabric.js for a project and it's great. It provides an abstraction layer for the canvas, and has an entire 'object manipulation layer/mask' that accompanies each object. I'd like to take it a step further and leverage it to make actual diagrams, with connections between objects, as well as have more 'metadata' that accompanies each object. Has anyone already done this already? Is Fabric.js the right choice for this? Any thoughts on how I would approach creating 'connector' objects between two objects that respond to events from the objects they're attached to? It's

Fabric.js clipping individual objects dynamically

只愿长相守 提交于 2019-11-28 05:06:08
问题 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

Fabricjs pan and zoom

点点圈 提交于 2019-11-28 04:34:38
How can I pan and zoom using fabricjs? I've tried using the methods zoomToPoint and setZoom but they do not work for panning. Once I start using different zoom points I start having trouble. $('#zoomIn').click(function(){ canvas.setZoom(canvas.getZoom() * 1.1 ) ; }) ; $('#zoomOut').click(function(){ canvas.setZoom(canvas.getZoom() / 1.1 ) ; }) ; $('#goRight').click(function(){ //Need to implement }) ; $('#goLeft').click(function(){ //Need to implement }) ; http://jsfiddle.net/hdramos/ux16013L/ Solved it using: relativePan() absolutePan() [Update] $('#goRight').click(function(){ var units = 10