Giter Site home page Giter Site logo

fabric-drawing-board-plugin's Introduction

fabric-drawing-board

Install

npm i --save fabric-drawing-board

How to use

Prepare your canvas element

<div style="width: 1000px;height: 600px">
	<!-- fabric-drawing-board automatically set the width and height of the canvas to the width and height of the canvas parent node -->
	<canvas id="myCanvasId"></canvas>
</div>
import FabricDrawingBoard from "fabric-drawing-board";

const fdb = new FabricDrawingBoard({ canvasId: "myCanvasId" });

Repo

Demo

or

  • clone this repo
  • npm install
  • npm run serve
  • open localhost:8080

APIs

init

const fdb = new FabricDrawingBoard({ canvasId: "myCanvasId" });

// or pass more params

const fdb = new FabricDrawingBoard({
	canvasId: "myCanvasId", // canvas element id, Required
	brushColor: "rgb(0, 0, 0)", // free draw color
	strokeColor: "rgb(0, 0, 0)", // stroke color of line, rect, circle, text
	fillColor: "rgba(0, 0, 0, 0)", // fill color of rect, circle
	bgColor: "rgba(0, 0, 0, 0)", // background color of canvas
	textEditBgColor: '#fff', // text edit area background color
	brushSize: 4, // free draw width
	strokeSize: 4, // stroke width of line, rect, circle
	eraserSize: 4, // eraser width
	fontSize: 18, // font size of text
});

getFabric()

// return fabric
const fabric = fdb.getFabric();

getFabricCanvas()

// return new fabric.Canvas()
const fabric_canvas = fdb.getFabricCanvas();

setBrushColor()

// set free draw color
fdb.setBrushColor("#000");
fdb.setBrushColor("rgb(0,0,0)");
fdb.setBrushColor("black");

setStrokeColor()

// set line, rect, circle, text stroke coloe
fdb.setStrokeColor("#000");
fdb.setStrokeColor("rgb(0,0,0)");
fdb.setStrokeColor("black");

setFillColor()

// set rect, circle fill color
fdb.setFillColor("#000");
fdb.setFillColor("rgb(0,0,0)");
fdb.setFillColor("rgba(0,0,0,0)");
fdb.setFillColor("black");

setBgColor()

// set canvas background color
fdb.setBgColor("#000");
fdb.setBgColor("rgb(0,0,0)");
fdb.setBgColor("rgba(0,0,0,0)");
fdb.setBgColor("black");

setTextEditBgColor()

// set text edit area background color
fdb.setTextEditBgColor("#000");
fdb.setTextEditBgColor("rgb(0,0,0)");
fdb.setTextEditBgColor("rgba(0,0,0,0)");
fdb.setTextEditBgColor("black");

setBrushSize()

// set free draw width
fdb.setBrushSize(4);

setEraserSize()

// set eraser width
fdb.setEraserSize(4);

setStrokeSize()

// set line, rect, circle stroke width
fdb.setStrokeSize(4);

setFontSize()

// set text font size
fdb.setFontSize(18);

drawBrush()

// draw freely on canvas
fdb.drawBrush();

drawLine()

// mouse to draw line freely on canvas
fdb.drawLine();

drawRect()

// use mouse to draw rect freely on canvas
fdb.drawRect();

drawCircle()

// use mouse to draw circle freely on canvas
fdb.drawCircle();

drawText()

// input everything on canvas
fdb.drawText();

useEraser()

// use mouse to erasing anything on canvas
fdb.useEraser();

useMove()

// use mouse to move canvas
fdb.useMove();

canvasZoomUp()

// enlarge canvas
fdb.canvasZoomUp();

canvasZoomDown()

// zoom out the canvas
fdb.canvasZoomDown();

canvasUndo()

// undo the current operation
fdb.canvasUndo();

canvasRedo()

// restore current operation
fdb.canvasRedo();

canvasClear()

// empty canvas
fdb.canvasClear();

canvasExport()

// export canvas to base64 data
fdb.canvasExport((data) => {
	// save to local or upload here
});

fabric-drawing-board-plugin's People

Contributors

cc4j 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.