Git Product home page Git Product logo

svg-path-to-canvas's Introduction

Convert SVG d path to canvas commands

针对一些不支持Path2D API的canvas环境(比如微信小程序),提供将svg path转换成canvas命令的方法。

<script src="https://s1.ssl.qhres.com/!e2cdf9c7/svg-path-to-canvas.min.js"></script>
npm install svg-path-to-canvas
const d = 'M23.6,0c-3.4,0-6.3,2.7-7.6,5.6C14.7,2.7,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,9.5,11.9,16,21.2 c6.1-9.3,16-12.1,16-21.2C32,3.8,28.2,0,23.6,0z'

const sp = new SvgPath(d)
const [cx, cy] = sp.center

const context = mycanvas.getContext('2d')

sp.save()
  .beginPath()
  .translate(-cx, -cy)
  .rotate(45)
  .scale(10)
  .translate(cx, cy)
  .translate(350, 350)
  .strokeStyle('red')
  .lineWidth(3)
  .to(context)
  .stroke()

svg-path-to-canvas's People

Contributors

akira-cn avatar hamger avatar

Stargazers

 avatar Brendan Beltz avatar Alrizki Pasca avatar RD avatar rexleimo avatar Francisco Ossian avatar  avatar 前端小然子 avatar kaely avatar Jiang Guoxi avatar PurpleManager avatar Gock avatar Black Jack avatar vfasky avatar jasonZhan avatar Nathan Botelho avatar Christopher James Allen avatar Stanislav Krasimirov Georgiev avatar  avatar  avatar monkeytao avatar Dolby avatar Roni Nes avatar JoeyKo avatar 清扬陌客 avatar David Authier avatar  avatar Даниил Пронин avatar vincentYang avatar laden avatar Iulian Gulea avatar Andrey avatar ik5 avatar Kousuke Ebihara avatar Mikhail Sidorov avatar  avatar  avatar Michael Jett avatar  avatar  avatar fri3nd avatar LongYinan avatar Lan Qingyong avatar lidongjies avatar Neal Caffery avatar

Watchers

 avatar  avatar James Cloos avatar  avatar  avatar

svg-path-to-canvas's Issues

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.