fabricjs

Contain a rotated object inside another rotated object FabricJS

牧云@^-^@ 提交于 2021-02-07 18:09:19
问题 I have two objects a parent (red) and a child (blue). The parent object is fixed and can't be moved , only the child object is movable and the child is always bigger than the parent. In whatever way the child object is moved it should always be contained inside the child, which means we should never see the red rectangle. Demo: https://codesandbox.io/s/force-contain-of-object-inside-another-object-fabric-js-7nt7q I know there are solutions to contain an object within the canvas or other

Contain a rotated object inside another rotated object FabricJS

被刻印的时光 ゝ 提交于 2021-02-07 18:03:49
问题 I have two objects a parent (red) and a child (blue). The parent object is fixed and can't be moved , only the child object is movable and the child is always bigger than the parent. In whatever way the child object is moved it should always be contained inside the child, which means we should never see the red rectangle. Demo: https://codesandbox.io/s/force-contain-of-object-inside-another-object-fabric-js-7nt7q I know there are solutions to contain an object within the canvas or other

Dynamic svg favicon?

孤街醉人 提交于 2021-02-06 09:08:44
问题 I have an icon as SVG. I want to have it in different colors as favicon. Since there isn't any toDataUrl() for SVG elements I don't see a solution that doesn't involve a server. Any idea for a client side solution? 回答1: fabric.js supports rendering of SVG elements into canvas elements. 回答2: This is not exactly what you asked, but here's a page testing the support for svg favicons in browsers. If the browser supports svg as favicon it's trivial to generate a data url from the svg markup and

Fabric toDataUrl with multiplier not working as expected

半城伤御伤魂 提交于 2021-01-29 03:00:46
问题 In my code I created method to clip images using fabric shapes. I have used stackoverflow answer for achieving this. Somehow after using this method I cannot render the canvas using default fabric canvas render method. var img01URL = 'https://www.google.com/images/srpr/logo4w.png'; var img02URL = 'http://fabricjs.com/lib/pug.jpg'; var canvas = new fabric.Canvas('c'); document.getElementById('download').addEventListener('click', function() { canvas.renderAll(); this.href = canvas.toDataURL({

fabric.js: bind event to background image

痞子三分冷 提交于 2021-01-28 23:38:08
问题 I'm trying to bind an event to a background image: var imgInstance = fabric.Image.fromURL(path, function(oImg) { oImg.on("selected", function() { alert(); }); canvas.setBackgroundImage(oImg, canvas.renderAll.bind(canvas), { top: 0, left: 0 }); oImg.on("selected", function() { alert(); }); }); I can get it work. I'm trying to bind mouse events to handle drag, so i can move the image when it's bigger than the canvas, like background-cover css property. Thoughts? Thanks guys! SOLUTION: var

fabric.js: bind event to background image

浪子不回头ぞ 提交于 2021-01-28 23:37:10
问题 I'm trying to bind an event to a background image: var imgInstance = fabric.Image.fromURL(path, function(oImg) { oImg.on("selected", function() { alert(); }); canvas.setBackgroundImage(oImg, canvas.renderAll.bind(canvas), { top: 0, left: 0 }); oImg.on("selected", function() { alert(); }); }); I can get it work. I'm trying to bind mouse events to handle drag, so i can move the image when it's bigger than the canvas, like background-cover css property. Thoughts? Thanks guys! SOLUTION: var

fabric.js 3.6 - Bounding box for group doesn't update when grouped objects are changed

人盡茶涼 提交于 2021-01-28 21:51:41
问题 The problem I'm having with fabric.js seems simple, but I've been searching for a solution without any luck, so here I am. I create a simple group to draw an arrow, consisting of a line object and a rotated triangle placed at its end point. This works fine, but when I dynamically update the stroke width of the line and the width/height of the triangle, the group's bounding box doesn't update to match the new dimensions. Here's an image of the result: Here's a live demo. Just drag the slider

Fabric js render of big image gives pixelated results

痴心易碎 提交于 2021-01-28 11:10:32
问题 I have to fit a big image (8000x6500) into a 800x650 canvas When I try to render the image simply using canvas.add() and having the image render at its 100% scale the resulting image is much more pixelated/blurred compared to the original one. This is the code I'm using (only the image is a little bit smaller but you can still see the issue): const canvas = new fabric.Canvas('c', { imageSmoothingEnabled: false }); fabric.Image.fromURL('http://cms.web.cern.ch/sites/cms.web.cern.ch/files/styles

How to animate line-drawing in Fabric

梦想的初衷 提交于 2021-01-28 05:53:11
问题 It is not very hard to animate line-drawing in clear Canvas, but i don't understand how do it in Fabric . For example i got this line : var L = new fabric.Line([50, 100, 200, 200], { left: 170, top: 150, stroke: 'red' }) and i need that one of its end started to continue till next point ( like a pencil drawing the line ). I know that there is a function 'animate' , but with L.animate('left', 50, { onChange: canvas.renderAll.bind(canvas), duration: 3000 }); my line only changes its top-left

How to put an html element over a fabric.js element

我是研究僧i 提交于 2021-01-28 05:22:45
问题 I want to put a button over a fabric.js element which is inside of a fabric.Group. How do I get the top-left corner coords relative to the canvas container of a fabric element and then set it to the button?. jsfiddle: https://jsfiddle.net/d9sp16yc/2/ I've tried things like this or this but I don't get the results that I want. The button gets slightly moved to right or left / bottom or top. Another thing is that the setSize function is scaling the group when the window gets resized (just to