# svg-path-to-canvas

> 针对一些不支持[Path2D](https://developer.mozilla.org/en-US/docs/Web/API/Path2D) API的canvas环境（比如微信小程序），提供将svg path转换成canvas命令的方法。

Latest version **1.11.3** (published 2019-04-22) · 0 weekly downloads

## Install

```sh
npm install svg-path-to-canvas
pnpm add svg-path-to-canvas
yarn add svg-path-to-canvas
bun add svg-path-to-canvas
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.11.3 |
| Published | 2019-04-22 |
| First published | 2018-03-27 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 304.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | akira-cn |
| Maintainers | akira_cn |

## Links

- npm: https://www.npmjs.com/package/svg-path-to-canvas
- npm.io page: https://npm.io/package/svg-path-to-canvas

## Dependencies (3)

- [sprite-math](https://npm.io/package/sprite-math.md) ^1.0.5
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0
- [point-at-length](https://npm.io/package/point-at-length.md) ^1.1.0

## Recent versions

- 1.11.3 (latest) — 2019-04-22
- 1.11.2 — 2019-04-22
- 1.11.1 — 2019-01-07
- 1.11.0 — 2019-01-04
- 1.10.1 — 2018-12-20
- 1.10.0 — 2018-12-19
- 1.9.6 — 2018-09-05
- 1.9.5 — 2018-08-03
- 1.9.4 — 2018-08-03
- 1.9.3 — 2018-07-23
- 1.9.2 — 2018-07-23
- 1.9.1 — 2018-07-23
- 1.9.0 — 2018-07-23
- 1.8.4 — 2018-07-23
- 1.8.2 — 2018-06-01
- … 18 more at https://npm.io/package/svg-path-to-canvas/versions

## README

# Convert SVG d path to canvas commands

针对一些不支持[Path2D](https://developer.mozilla.org/en-US/docs/Web/API/Path2D) API的canvas环境（比如微信小程序），提供将svg path转换成canvas命令的方法。

```html
<script src="https://s1.ssl.qhres.com/!e2cdf9c7/svg-path-to-canvas.min.js"></script>
```

```bash
npm install svg-path-to-canvas
```

```js
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()
```

![](https://p1.ssl.qhimg.com/t0169d65a65437938a7.png)

---
_Source: https://npm.io/package/svg-path-to-canvas · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
