Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser
Find a file
2010-07-14 09:25:23 -04:00
dist Update distribution and minified distribution files. 2010-07-13 16:19:08 -04:00
lib Prototype.js and APE.js are no longer dependencies (shrinking overall size of fabric.js by ~150KB). Add json2.js and a simple base library (still needs tests). 2010-06-17 10:00:47 -04:00
src Fix loading order of objects in loadFromDatalessJSON. Fix few unit tests. 2010-07-13 16:17:33 -04:00
test Change conditional comments so that excanvas.js is only downloaded in IE<9. 2010-07-14 09:25:23 -04:00
fabric.js Rename canvas_*.class.js files to just *.class.js 2010-07-09 21:50:13 -04:00
LICENSE Specify that license is MIT. 2010-07-09 11:21:03 -04:00
README.md Make description more descriptive. Add IE9pre3 to the list of supported browsers. 2010-07-13 17:53:55 -04:00

Fabric.js is a framework that makes it easy to work with HTML5 canvas element. It is an interactive object model on top of canvas element. It is also an SVG-to-canvas parser.

Using Fabric.js, you can create and populate objects on canvas; objects like simple geometrical shapes — rectangles, circles, ellipses, polygons, or more complex shapes consisting of hundreds or thousands of simple paths. You can then scale, move, and rotate these objects with the mouse; modify their properties — color, transparency, z-index, etc. You can also manipulate these objects altogether — grouping them with a simple mouse selection.

Goals

  • Unit tested (939 tests at the moment)
  • Modular (~20 small "classes")
  • Cross-browser
  • Fast
  • Encapsulated in one object
  • No browser sniffing for critical functionality

Supported browsers

  • Firefox 2+
  • Safari 3+
  • Opera 9.64+
  • Chrome 1+
  • IE9pre3

Building

  1. Install Sprockets

     $ gem install --remote sprockets
    
  2. Build distribution file

     $ sprocketize fabric.js > dist/all.js
    
  3. Create a minified distribution file

     $ java -jar lib/yuicompressor-2.4.2.jar dist/all.js -o dist/all.min.js
    

Examples of use

Adding red rectangle to canvas

<canvas id="canvas" width="300" height="300"></canvas>  
...

var canvas = new fabric.Element('canvas');

var rect = new fabric.Rect({
  top: 100,
  left: 100,
  width: 60,
  height: 70,
  fill: 'red'
});

canvas.add(rect);

Object Model hierarchy

  fabric.Object
    |
    -- fabric.Line
    |
    -- fabric.Circle
    |
    -- fabric.Ellipse
    |
    -- fabric.Rect
    |
    -- fabric.Polyline
    |
    -- fabric.Polygon
    |
    -- fabric.Group
    |
    -- fabric.Text
    |
    -- fabric.Image
    |
    -- fabric.Path
         |
         -- fabric.PathGroup
  
  
  fabric.util
    |
    -- removeFromArray
    |
    -- degreesToRadians
    |
    -- toFixed
    |
    -- getRandomInt

  
  Canvas
    |
    -- parseAttributes
    |
    -- parseElements
    |
    -- parseStyleAttribute
    |
    -- parsePointsAttribute
  
  
  fabric.Element

  fabric.Point

  fabric.Intersection

  fabric.Color

Credits

License

MIT License

TODO

  • All methods under fabric.util.* (except misc.js) need unit tests