-
Just simple drawing board lib by fabric
npm i --save fabric-drawing-board
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" });
or
- clone this repo
- npm install
- npm run serve
- open localhost:8080
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
});
// return fabric
const fabric = fdb.getFabric();
// return new fabric.Canvas()
const fabric_canvas = fdb.getFabricCanvas();
// set free draw color
fdb.setBrushColor("#000");
fdb.setBrushColor("rgb(0,0,0)");
fdb.setBrushColor("black");
// set line, rect, circle, text stroke coloe
fdb.setStrokeColor("#000");
fdb.setStrokeColor("rgb(0,0,0)");
fdb.setStrokeColor("black");
// set rect, circle fill color
fdb.setFillColor("#000");
fdb.setFillColor("rgb(0,0,0)");
fdb.setFillColor("rgba(0,0,0,0)");
fdb.setFillColor("black");
// set canvas background color
fdb.setBgColor("#000");
fdb.setBgColor("rgb(0,0,0)");
fdb.setBgColor("rgba(0,0,0,0)");
fdb.setBgColor("black");
// 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");
// set free draw width
fdb.setBrushSize(4);
// set eraser width
fdb.setEraserSize(4);
// set line, rect, circle stroke width
fdb.setStrokeSize(4);
// set text font size
fdb.setFontSize(18);
// draw freely on canvas
fdb.drawBrush();
// mouse to draw line freely on canvas
fdb.drawLine();
// use mouse to draw rect freely on canvas
fdb.drawRect();
// use mouse to draw circle freely on canvas
fdb.drawCircle();
// input everything on canvas
fdb.drawText();
// use mouse to erasing anything on canvas
fdb.useEraser();
// use mouse to move canvas
fdb.useMove();
// enlarge canvas
fdb.canvasZoomUp();
// zoom out the canvas
fdb.canvasZoomDown();
// undo the current operation
fdb.canvasUndo();
// restore current operation
fdb.canvasRedo();
// empty canvas
fdb.canvasClear();
// export canvas to base64 data
fdb.canvasExport((data) => {
// save to local or upload here
});