GithubHelp home page GithubHelp logo

canvas-sign's Introduction

canvas-sign

打造canvas签名组件

Use

npm install canvas-sign-online --save

支持pc和移动端,核心代码plugin/canvas-sign.js
第一步初始化并且设置容器大小:

import CanvasSign from "canvas-sign-online";

const cv = document.getElementById("canvas");
const canvas = new CanvasSign(cv);
/** 注意:canvas的宽高需要在属性上设置,而不是style */
cv.width = '500';
cv.height = '500';

第二步画笔设置样式:

canvas.setLineStyle({
    strokeStyle: "black",
    lineWidth: 2,
    shadowBlur: '1',
    lineCap: 'round',
    shadowColor: 'black',
    lineJoin: 'round',
})

接下来就是自由绘制了。
绘制完成过后导出:

const img = document.createElement("a");
img.href = canvas.getPNGImage();
img.download = "canvas-sign.png";
img.style.display = "none";
document.body.appendChild(img);
img.click();
document.body.removeChild(img);

导入json:

canvas.loadJson(dataJson);

api列表:

api Description Note
getPNGImage png格式导出
getJPGImage jpg格式导出
clear 清除画板
setLineStyle 设置画笔样式 同原生canvas 样式和颜色
toJson 导出json
loadJson 加载已经导出的json toJson().dataJson

最后,祝使用愉快!

Realization idea

实现思路以及细节参考:canvas在线签名插件
如果有什么问题或好的想法欢迎在参与讨论。

canvas-sign's People

Contributors

javascript-wei avatar tu6ge avatar

Watchers

 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.