fabricjs

How to upload an image to a canvas with Fabric.js?

走远了吗. 提交于 2019-11-29 02:50:01
问题 I want that to create a process where the users can upload their images and then edit them in the browser in a Canvas with Fabric.js using some buttons -wich uses Fabric.js to add some effects-. I can't make it work. My HTML is: <form id="uploadImg" runat="server"> <input type="file" id="uploadedImg"/> </form> <canvas id="canvas"></canvas> The Javascript is the following: var canvas = new fabric.Canvas('canvas'); canvas.setHeight(480); canvas.setWidth(640); $('#uploadedImg').change(function (

Applying rounded corners to paths/polygons

断了今生、忘了曾经 提交于 2019-11-29 02:28:21
问题 I'm gathering some info for a project that has to start within a few weeks. This project contains a browser-based drawing tool where users can add predefined shapes or forming shapes themselves. Shapes must be selectable, freely scalable and rotatable with a Illustrator-like transformtool (handles). Predefined shapes that we have in mind are: rectangles, ellipses, half ellipses and (isosceles) triangles. So far so good, to achieve this I was thinking of RaphaelJS or FabricJS but... Every

Canvas coordinates in Fabric.js have offset

戏子无情 提交于 2019-11-28 22:04:06
I just started with fabric.js and I have a (probably beginner) error: I am using fabric with jquery with the following code: $(document).ready(function () { canvas = new fabric.StaticCanvas('scroller'); canvas.add( new fabric.Rect({ top: 0, left: 0, width: 140, height: 100, fill: '#f55' }) ); }); This code should draw a 140x100 Rectangle on the canvas. Sadly, only a quarter of the Rectangle appears. If I change the top and left values to higher numbers, more of the Rectangle appears on the canvas. So it seems, that the canvas origin is not at 0/0, but at sth. higher. Does someone know how to

Image zoom centered on mouse position

爷,独闯天下 提交于 2019-11-28 21:41:17
I am writing a script with Fabric.js to zoom an image at the current mouse position. I have made some progress but there is an error somewhere. Case 1 : Keep the mouse at one point and zoom with the mouse wheel. Result: Works perfectly, image zooms at that particular pixel. Case 2: Zoom in a little at one position (3-5 times with mouse wheel), then move the mouse to a new position and zoom in there. Result: Works fine for the first point, but after moving to another point and zooming, the image position is incorrect. My code is in this fiddle: https://jsfiddle.net/gauravsoni/y3w0yx2m/1/ I

fabric.js resize canvas to fit screen

a 夏天 提交于 2019-11-28 19:47:56
I'm currently developping an application on mobile device (android and iPhone) with ionic and cordova. I would like to edit a picture. I use fabric.js library to do that. Fabric.js converts an image and other items into canvas. Then I add some image on the canvas (stickers) and export it as an image(dataURL). So the size of the canvas is really important because it is a quality factor (export an image based on small canvas will result in poor quality). The canvas size is about 607*1080 pixel (depending on the device that took the photo). I would like to fit it in the screen without losing

Loading JSON in canvas with fabric.js

佐手、 提交于 2019-11-28 19:23:15
问题 I am trying to save data in JSON and load it back into the canvas with fabric.js I keep getting errors likep with the following simple code: canvas.add(new fabric.Rect({ width: 50, height: 50, fill: 'red', top: 100, left: 100 })); var c = canvas.toJSON(); canvas.clear(); canvas.loadFromJSON(c); I get: SyntaxError: JSON.parse: unexpected character [Break On This Error] var Cufon=(function(){var k=function()....Image.fromElement.async=true})(this); When I use my own JSON, It validates well, but

Scale fabric.js canvas objects

大城市里の小女人 提交于 2019-11-28 17:50:36
问题 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

Move object within canvas boundary limit

感情迁移 提交于 2019-11-28 17:32:06
I am trying to limit the moving object within the canvas but i am getting some difficulty to moving object with limit area on top and left side and when i scale the object with big size that time also i am not able to limit the moving object on left and top side of the canvas canvas.observe("object:moving", function(e){ var obj = e.target; // if object is too big ignore if(obj.currentHeight > obj.canvas.height || obj.currentWidth > obj.canvas.width){ return; } var halfw = obj.currentWidth/2; var halfh = obj.currentHeight/2; var bounds = {tl: {x: halfw, y:halfh}, br: {x: obj.canvas.width-halfw,

Drag and Drop into Fabric.js canvas

☆樱花仙子☆ 提交于 2019-11-28 17:06:55
How can I drop items (like image, or other object from other canvas) into canvas which is managed by fabricjs? I have found many examples how to move items inside canvas but I would like to drag and drop item from outer element into canvas. Since you asked for an example and I haven't tried it out myself yet, here goes: Example Fiddle Markup <div id="images"> <img draggable="true" src="http://i.imgur.com/8rmMZI3.jpg" width="250" height="250"></img> <img draggable="true" src="http://i.imgur.com/q9aLMza.png" width="252" height="295"></img> <img draggable="true" src="http://i.imgur.com/wMU4SFn

Undo-Redo feature in Fabric.js

若如初见. 提交于 2019-11-28 17:05:00
Is there any built-in support for for undo/redo in Fabric.js? Can you please guide me on how you used this cancel and repeat in [http://printio.ru/][1] Tom In http://jsfiddle.net/SpgGV/9/ , move the object and change its size. If the object state is changed, and then we do undo/redo, its previous state will be deleted when the next change comes. It makes it easier to do undo/redo. All events of canvas should be called before any element is added to canvas. I didn't add an object:remove event here. You can add it yourself. If one element is removed, the state and list should be invalid if this