Giter Site home page Giter Site logo

chaoshengzhang / fabric.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fabricjs/fabric.js

0.0 0.0 0.0 218.36 MB

Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser

Home Page: http://fabricjs.com

License: Other

JavaScript 55.59% TypeScript 44.22% CSS 0.01% HTML 0.05% Mustache 0.13%

fabric.js's Introduction

Fabric.js

A simple and powerful Javascript HTML5 canvas library.


๐Ÿฉบ ๐Ÿงช CodeQL


cdnjs jsdelivr Gitpod Ready-to-Code

NPM Downloads per month Bower


Sponsor asturur Sponsor melchiar Sponsor ShaMan123 Patreon


Features

  • Out of the box interactions such as scale, move, rotate, skew, group...
  • Built in shapes, controls, animations, image filters, gradients, patterns, brushes...
  • JPG, PNG, JSON and SVG i/o
  • Typed and modular
  • Unit tested

Supported Browsers/Environments

Context Supported Version Notes
Firefox โœ”๏ธ modern version (tbd)
Safari โœ”๏ธ version >= 10.1
Opera โœ”๏ธ chromium based
Chrome โœ”๏ธ modern version (tbd)
Edge โœ”๏ธ chromium based
Edge Legacy โŒ
IE11 โŒ
Node.js โœ”๏ธ Node.js installation

Fabric.js Does not use transpilation by default, the browser version we support is determined by the level of canvas api we want to use and some js syntax. While JS can be easily transpiled, canvas API can't.

Installation

$ npm install fabric --save
// or
$ yarn add fabric
// es6 imports
import { fabric } from 'fabric';

//  or cjs
const fabric = require('fabric').fabric;

Browser

cdnjs jsdelivr

See browser modules for using es6 imports in the browser or use a dedicated bundler.

Node.js

Fabric.js depends on node-canvas for a canvas implementation (HTMLCanvasElement replacement) and jsdom for a window implementation on node. This means that you may encounter node-canvas limitations and bugs.

Follow these instructions to get node-canvas up and running.

Quick Start

Plain HTML
<canvas id="canvas" width="300" height="300"></canvas>

<script src="https://cdn.jsdelivr.net/npm/fabric"></script>
<script>
  const canvas = new fabric.Canvas('canvas');
  const rect = new fabric.Rect({
    top: 100,
    left: 100,
    width: 60,
    height: 70,
    fill: 'red',
  });
  canvas.add(rect);
</script>
ReactJS
import React, { useEffect, useRef } from 'react';
import { fabric } from 'fabric';

export const FabricJSCanvas = () => {
  const canvasEl = useRef(null);
  useEffect(() => {
    const options = { ... };
    const canvas = new fabric.Canvas(canvasEl.current, options);
    // make the fabric.Canvas instance available to your app
    updateCanvasContext(canvas);
    return () => {
      updateCanvasContext(null);
      canvas.dispose();
    }
  }, []);

  return (<canvas width="300" height="300" ref={canvasEl}/>)
});
Node.js
const http = require('http');
const { fabric } = require('fabric');

const port = 8080;

http
  .createServer((req, res) => {
    const canvas = new fabric.Canvas(null, { width: 100, height: 100 });
    const rect = new fabric.Rect({ width: 20, height: 50, fill: '#ff0000' });
    const text = new fabric.Text('fabric.js', { fill: 'blue', fontSize: 24 });
    canvas.add(rect, text);
    canvas.renderAll();
    if (req.url === '/download') {
      res.setHeader('Content-Type', 'image/png');
      res.setHeader('Content-Disposition', 'attachment; filename="fabric.png"');
      canvas.createPNGStream().pipe(res);
    } else if (req.url === '/view') {
      canvas.createPNGStream().pipe(res);
    } else {
      const imageData = canvas.toDataURL();
      res.writeHead(200, '', { 'Content-Type': 'text/html' });
      res.write(`<img src="${imageData}" />`);
      res.end();
    }
  })
  .listen(port, (err) => {
    if (err) throw err;
    console.log(
      `> Ready on http://localhost:${port}, http://localhost:${port}/view, http://localhost:${port}/download`
    );
  });

Other Solutions

Project Description Demo
Three.js 3D graphics
PixiJS WebGL renderer
Konva Similar features โŒ
Canvas2PDF PDF renderer
html-to-image HTML to image/canvas

More Resources

Credits Patreon

fabric.js's People

Contributors

kangax avatar asturur avatar kienz avatar shaman123 avatar gordorank avatar inssein avatar twffy avatar rodovich avatar garg avatar sapics avatar stefanhayden avatar melchiar avatar davidjrice avatar sorich87 avatar sjpemberton avatar kjtsanaktsidis avatar rykerwilliams avatar rockerboo avatar xhmikosr avatar timandres avatar melight avatar zigotica avatar msievers avatar miracle2k avatar jafferhaider avatar baltauger avatar durga598 avatar briefbanane avatar incuuu avatar ncou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.