# FabricJS
**Repository Path**: zhaisss/FabricJS
## Basic Information
- **Project Name**: FabricJS
- **Description**: Fabric.js 是一个在服务器端运行的 Node.js 扩展模块,用于在Web上绘制各种图形的 JS 库
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 8
- **Created**: 2022-06-24
- **Last Updated**: 2024-11-25
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Fabric.js
FabricJS.com is a **simple and powerful Javascript HTML5 canvas library**. It is also an **SVG-to-canvas parser**.
[](http://travis-ci.org/#!/kangax/fabric.js)
[](https://codeclimate.com/github/kangax/fabric.js)
[](https://gitpod.io/#https://github.com/fabricjs/fabric.js)
[](https://cdnjs.com/libraries/fabric.js)
[](http://badge.fury.io/js/fabric)
[](https://www.npmjs.org/package/fabric)
[](http://badge.fury.io/bo/fabric)
## Features
- drag-n-drop objects on canvas,
- scale, move, rotate and group objects with mouse,
- use predefined shapes or create custom objects,
- works super-fast with many objects,
- supports JPG, PNG, JSON and SVG formats,
- ready-to-use image filters,
- create animations,
- and much more!
Introduction
•
Docs
•
Demos
•
Kitchensink
•
Benchmarks
•
Contribution
## Quick Start
```
$ npm install fabric --save
```
After this, you can import fabric like so:
```
const fabric = require("fabric").fabric;
```
Or you can use this instead if your build pipeline supports ES6 imports:
```
import { fabric } from "fabric";
```
NOTE: If you are using Fabric.js in a Node.js script, you will depend on [node-canvas](https://github.com/Automattic/node-canvas). `node-canvas` is an HTML canvas replacement that works on top of native libraries. Please [follow the instructions](https://github.com/Automattic/node-canvas#compiling) to get it up and running.
NOTE: es6 imports won't work in browser or with bundlers which expect es6 module like vite. Use commonjs syntax instead.
## Usage
### Plain HTML
```html
```
### ReactJS
```tsx
import React, {useEffect, useRef} from 'react'
import {fabric} from 'fabric'
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 (