fabricjs

How to get polygon points in Fabric.js

耗尽温柔 提交于 2019-11-27 03:38:26
问题 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? 回答1: Polygon points are relative to

How to edit a FabricJS IText and apply new styles (e.g. highlighting, etc…)

强颜欢笑 提交于 2019-11-27 01:47:32
问题 I want to edit the highlighted characters in a text in canvas using fabric.js, like change its color, font, style etc. just like this http://fabricjs.com/test/misc/itext.html to @user43250937 hey uhm. I tried it and it works! :D thanks. I tried Underline, Bold, Italic, but I have a problem changing the color of the text, I tried : // "cinput" is the id of the color picker. addHandler('cinput', function(obj) { var color = $("#cinput").val(); var isColor = (getStyle(obj, 'fill') || '').indexOf

Fabricjs pan and zoom

China☆狼群 提交于 2019-11-27 00:30:35
问题 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

Fabricjs How to scale object but keep the border (stroke) width fixed

跟風遠走 提交于 2019-11-26 23:21:41
问题 I'm developing a diagram tool based on fabricjs. Our tool has our own collection of shape, which is svg based. My problem is when I scale the object, the border (stroke) scale as well. My question is: How can I scale the object but keep the stroke width fixed. Please check the attachments. Thank you very much! 回答1: Here is an easy example where on scale of an object we keep a reference to the original stroke and calculate a new stroke based on the scale. var canvas = new fabric.Canvas('c', {

Fit the background image to canvas size with Fabric js

主宰稳场 提交于 2019-11-26 22:18:26
问题 I am trying to stretch the background image so it can fit the canvas size. But its not working. I have followed this question and based on comment i have implemented the stretching code. Strech the background image to canvas size with Fabric.js http://fabricjs.com/docs/fabric.Canvas.html#setBackgroundImage Code $(function () { var canvas1 = new fabric.Canvas('canvas1'); //Default var canvas = canvas1; //Change background using Image document.getElementById('bg_image').addEventListener('change

What is the best practice to export canvas with high quality images?

人盡茶涼 提交于 2019-11-26 21:59:38
I need your help. I explain my situation: I’m using fabric.js library to place shapes, text, etc. in my application. My canvas size has 1000x1000 pixels (about 26.45x26.45 centimeters). I have an image upload script only for upload images in high quality, like 300 dpi. Basically what I do is the following: - draw the canvas (uploading images, put text, etc…); - resize the canvas multiplying by scale factor to be able at the end to have an image with 300dpi; - save the canvas in PNG format; - using php/ajax and Imagick, put the canvas with 300 dpi quality, saving in jpg format. The problem is:

Multiple clipping areas on Fabric.js canvas

女生的网名这么多〃 提交于 2019-11-26 21:53:04
For making Photo Collage Maker , I use fabric js which has object based clipping feature. This feature is great but image inside that clipping region cannot be scaled, moved or rotated. I want fixed position clipping region and image can be positioned inside the fixed clipping area as user want. I googled and find very near solution var canvas = new fabric.Canvas('c'); var ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.rect(10,10,150,150); ctx.rect(180,10,200,200); ctx.closePath(); ctx.stroke(); ctx.clip(); Multiple Clipping Areas on fabric js canvas where image of one clipping region is

Prevent Fabric js Objects from scaling out of the canvas boundary

谁说胖子不能爱 提交于 2019-11-26 21:46:21
问题 I have been trying to keep an object (constructed in fabric js over a canvas) inside the boundaries at all the times. It has been achieved at moving and rotating it. I took help from Move object within canvas boundary limit for achieving this. But when I start to scale the object, it simply keeps on going out of boundary. I do not understand what has to be done to keep it inside the boundary only, even while scaling. Please help me with a code to prevent this behavior. It would be great if

Add image from user computer to canvas

我的未来我决定 提交于 2019-11-26 21:37:05
问题 i'm working on a web app that allow users to create dynamic slideshow. Currently i've got an issue regardless how to add image from the computer's user to the canvas. I'm using a input button to get the file from the computer and it appeal a function who will add the image to the canvas. So far i've tried different ways to add the image to the canvas as well as this one : Dynamically add image to canvas But the code showing here doesnt work in my case, because it just draw the image into the

Fabric.js - how to save canvas on server with custom attributes

Deadly 提交于 2019-11-26 19:28:49
I'd like to be able to save the current canvas' state to a server-side database, probably as a JSON string, and then later restore it with loadFromJSON . Typically, this is easily accomplished using: var canvas = new fabric.Canvas(); function saveCanvas() { // convert canvas to a json string var json = JSON.stringify( canvas.toJSON() ); // save via xhr $.post('/save', { json : json }, function(resp){ // do whatever ... }, 'json'); } And then function loadCanvas(json) { // parse the data into the canvas canvas.loadFromJSON(json); // re-render the canvas canvas.renderAll(); // optional canvas